私はZFを初めて使用します。私はapplication.ini
ここにコードを書きました:
[development]
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.view.encoding = "utf-8"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
resources.DB.adapter = "pdo_mysql"
resources.DB.params.host = "localhost"
resources.DB.params.username = "root"
resources.DB.params.password = ""
resources.DB.params.dbname = "xyz"
これが私のindex.phpです
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'development'));
// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
get_include_path(),
)));
/** Zend_Application */
require_once 'Zend/Application.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()->run();
これが私のbootstrap.phpです
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
protected function _initDoctype(){
$this->bootstrap('view');
$view = $this->getResource('view');
$view->doctype(Zend_View_Helper_Doctype::HTML5);
}
}
今最初に私はこのように私の接続をしました
$params = array('host' => 'localhost',
'username' => 'root',
'password' => '',
'dbname' => 'xyz'
);
$DB = new Zend_Db_Adapter_Pdo_Mysql($params);
$DB->setFetchMode(Zend_Db::FETCH_OBJ);
Zend_Registry::set('DB',$DB);
クエリの後半で、これを使用してレコードを取得しました。
$registry = Zend_Registry::getInstance();
$DB = $registry['DB']; and than my query
設定を変更したので、ブートストラップを含めてapplication.ini
、私が行ったのと同じことをどのように達成するのですか?私のアプリではすべてがそのようなものだからです。
今、私はこのエラーを受け取っています。
注意:未定義のインデックス:DB in
C:\ xampp \ htdocs \ xyz \ application \ controllers \ LoginController.php(59行目
)致命的なエラー:C:\ xampp \ htdocs \ xyz \ application \ controllers \ LoginController内の非オブジェクトでメンバー関数select()を呼び出します64行目の.php
59行目は
$registry = Zend_Registry::getInstance();
$DB = $registry['DB'];
64行目は
$select = $DB->select()
->from(array('p' => 'phone_service'))
->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
->where('u.user_preferences_name = ?', 'is_user_package_active')
->where('p.user_id = ?', $user_id);
編集済み
if($result->isValid()){
$data = $authAdapter->getResultRowObject(null,'password');
$auth->getStorage()->write($data);
$this->_redirect('/login/controlpannel');}
今、私のクエリは$user_id
ここで見つけることができません
$data = Zend_Auth::getInstance()->getStorage()->read();
$user_id = $data->user_id;
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
$select = $DB->select()
->from(array('p' => 'phone_service'))
->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
->where('u.user_preferences_name = ?', 'is_user_package_active')
->where('p.user_id = ?', $user_id);
そのため、このエラーが発生します
注意:.phtmlファイルで非オブジェクトのプロパティを取得しようとしています