私はzendを初めて使用し、MVCでどのように機能するかをほぼ理解していますが、MVC以外のプロジェクトではzend_authのみを使用しようとしています。login(auth)の部分は機能しますが(それが最善の方法かどうかわからない場合でも)、別のユーザーのデータ(ユーザーがログインしたときに保存される)を取得する方法がわかりませんページ。これが私のlogin.phpです:
<?php
ini_set('display_errors', 1);
// define an absolute path to library directory
// you don't have to set a constant but it is just good practice
// you can also use a variable or add the path directly below
define('APPLICATION_LIBRARY','c:/xampp/htdocs/website/');
// Note again: the path is the parent of your Zend folder, not the Zend folder itself.
// now set the include path
set_include_path(implode(PATH_SEPARATOR, array(
APPLICATION_LIBRARY, get_include_path(),
)));
include("config.php");
// i'm testing with a username and password that i know is inside database in the actual code is: $username= $_POST['username'] and the same for password.
$username ='userx';
$password = 'passx';
$auth = Zend_Auth::getInstance();
$adapter = new Zend_Auth_Adapter_DbTable($db);
$adapter ->setTableName('profiles')
->setIdentityColumn('username')
->setCredentialColumn('password')
->setIdentity($username)
->setCredential($password);
$result = $auth->authenticate($adapter);
switch($result->getCode()) {
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
$errorMessage = "Error: Name not correct.";
// i'm sending username and password to another login that is exactly like this one, but searches in another table
header("Location: login2.php?pass=".$password."&user=".$username);
break;
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
$errorMessage = "Error: pass and user are not valid";
echo $errorMessage;
header("Location: login2.php?pass=".$password."&user=".$username);
break;
case Zend_Auth_Result::SUCCESS:
$adapter->getResultRowObject();
$authStorage = $auth->getStorage(); // set storage. Session default
$authStorage->write($result); // save user data
if(isset($_POST['remember'])) {
Zend_Session::rememberMe(60*60*24*7*4);
$remember=$_POST['remember'];
}
// send user to page they originally request, with username and pass because i don't know how to get them there from what i've stored before...i know it's not good.
header("Location: profile_page.php?pass=".$password."&user=".$username."&remember=".$remember);
break;
default:
$errorMessage = "Error.";
break;
}
?>
これは私のconfig.phpファイルです:
<?php
error_reporting(E_ALL);
require_once('Zend/Session/Namespace.php');
require_once('Zend/Session.php');
require_once('Zend/Db/Table/Abstract.php');
require_once('Zend/Auth/Adapter/DbTable.php');
require_once('Zend/Auth.php');
require_once('Zend/Db/Expr.php');
require_once('Zend/Auth/Exception.php');
require_once('Zend/Controller/Action.php');
$params = array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => '',
'dbname' => 'website',
);
try {
$db = Zend_Db::factory('Pdo_Mysql', $params);
$db->getConnection();
} catch(Zend_Db_Adapter_Exception $e) {
die("<pre>There was an error connecting to the server</pre>"); //Probably bad login or mysql daemon is not running.
} catch(Zend_Exception $e) {
die("<pre>Something failed to load</pre>"); //factory() probably failed to load the adapter class
}
$users = new Zend_Session_Namespace('Zend_Auth');
?>
ユーザーが自分のプロファイルページで認証されたときに保存されるデータを取得したい。