ZF2 - Database configuration?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

ZF2 - Database configuration?

omerida
I'm taking a look at the ZF2 beta, and have made some progress in
wrapping my head around it. I like the modular approach to MVC, however,
one thing I haven't been able to figure out is how to set the database
configuration for things like Zend\Db\Table or
Zend\Authenticatoin\Adapter\DbTable to use.

Can DI help or is there somewhere else to register the default db adapter?

Thanks,

Oscar M.

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: ZF2 - Database configuration?

Marco Pivetta
Hey :)
I'm not sure this works, but please take a look at https://gist.github.com/1360533

Marco Pivetta
http://twitter.com/Ocramius
http://marco-pivetta.com



On 12 November 2011 07:17, Oscar Merida [via Zend Framework Community] <[hidden email]> wrote:
I'm taking a look at the ZF2 beta, and have made some progress in
wrapping my head around it. I like the modular approach to MVC, however,
one thing I haven't been able to figure out is how to set the database
configuration for things like Zend\Db\Table or
Zend\Authenticatoin\Adapter\DbTable to use.

Can DI help or is there somewhere else to register the default db adapter?

Thanks,

Oscar M.

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]





If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/ZF2-Database-configuration-tp4033733p4033733.html
To unsubscribe from Zend Framework Community, click here.
See how NAML generates this email

Reply | Threaded
Open this post in threaded view
|

I am facing this error when i run query to databse

vindu525
This post has NOT been accepted by the mailing list yet.
In reply to this post by omerida
Page not found

Exception information:

Message: Action "list" does not exist and was not trapped in __call()

Stack trace:

#0 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Action.php(518): Zend_Controller_Action->__call('listAction', Array)
#1 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('listAction')
#2 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#3 C:\xampp\htdocs\LC_Case\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#4 C:\xampp\htdocs\LC_Case\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#5 C:\xampp\htdocs\LC_Case\public\index.php(26): Zend_Application->run()
#6 {main}  
Request Parameters:

array (
  'controller' => 'signup',
  'action' => 'create',
  'module' => 'default',
  'id' => '',
  'fullname' => 'aravind',
  'username' => 'vindu525',
  'password' => 'vindu525',
  'email' => 'vindu525@gmail.com',
  'dob' => '5-25-1992',
  'gender' => 'Male',
  'submit' => 'Sign Up',
)  

//create action method
 public function createAction()
    {
        $userForm = new Form_SignUpForm();
                if($this->_request->isPost())
                {
                        if($userForm->isValid($_POST))
                        {
                                $userModel = new Model_SignUpForm();
                                $userModel->createUser(
                                        $userForm->getValue('firstname'),
                                        $userForm->getValue('username'),
                                        $userForm->getValue('password'),
                                        $userForm->getValue('email'),
                                        $userForm->getValue('dob'),
                                        $userForm->getValue('gender')
                                );
                                return $this->_forward('list');
                        }
                }

Anybody please help....
Reply | Threaded
Open this post in threaded view
|

Re: I am facing this error when i run query to databse

Marco Pivetta
You just don't have an indexAction in your controller :)
Marco Pivetta
http://twitter.com/Ocramius
http://marco-pivetta.com



On 12 November 2011 21:19, vindu525 [via Zend Framework Community] <[hidden email]> wrote:
Page not found

Exception information:

Message: Action "list" does not exist and was not trapped in __call()

Stack trace:

#0 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Action.php(518): Zend_Controller_Action->__call('listAction', Array)
#1 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('listAction')
#2 C:\xampp\htdocs\LC_Case\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#3 C:\xampp\htdocs\LC_Case\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#4 C:\xampp\htdocs\LC_Case\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#5 C:\xampp\htdocs\LC_Case\public\index.php(26): Zend_Application->run()
#6 {main}  
Request Parameters:

array (
  'controller' => 'signup',
  'action' => 'create',
  'module' => 'default',
  'id' => '',
  'fullname' => 'aravind',
  'username' => 'vindu525',
  'password' => 'vindu525',
  'email' => '[hidden email]',
  'dob' => '5-25-1992',
  'gender' => 'Male',
  'submit' => 'Sign Up',
)  

//create action method
 public function createAction()
    {
        $userForm = new Form_SignUpForm();
                if($this->_request->isPost())
                {
                        if($userForm->isValid($_POST))
                        {
                                $userModel = new Model_SignUpForm();
                                $userModel->createUser(
                                        $userForm->getValue('firstname'),
                                        $userForm->getValue('username'),
                                        $userForm->getValue('password'),
                                        $userForm->getValue('email'),
                                        $userForm->getValue('dob'),
                                        $userForm->getValue('gender')
                                );
                                return $this->_forward('list');
                        }
                }

Anybody please help....


If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/ZF2-Database-configuration-tp4033733p4035186.html
To unsubscribe from Zend Framework Community, click here.
See how NAML generates this email

Reply | Threaded
Open this post in threaded view
|

Re: I am facing this error when i run query to databse

vindu525
Thank you Marco pivetta

The values are getting inserted into the database , but still i dont know why this error occuring

//complete controller


<?php

class SignupController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $auth = Zend_Auth::getInstance();
                if($auth->hasIdentity()){
                        $this->view->identity = $auth->getIdentity();
                        }
    }

    public function createAction()
    {
        $userForm = new Form_SignUpForm();
                if($this->_request->isPost())
                {
                        if($userForm->isValid($_POST))
                        {
                                $userModel = new Model_SignUpForm();
                                $userModel->createUser(
                                        $userForm->getValue('fullname'),
                                        $userForm->getValue('username'),
                                        $userForm->getValue('password'),
                                        $userForm->getValue('email'),
                                        $userForm->getValue('dob'),
                                        $userForm->getValue('gender')
                                );
                                return $this->_forward('list');
                        }
                }
                               
                $userForm->setAction('/LC_Case/public/signup/create');
                $this->view->form = $userForm;
    }
       
        public function loginAction()
        {
                $userForm = new Form_SignUpForm();
                $userForm->setAction('/LC_Case/public/signup/login');
                $userForm->removeElement('fullname');
                $userForm->removeElement('username');
                $userForm->removeElement('dob');
                $userForm->removeElement('gender');
                $this->view->form = $userForm;
               
                if($this->_request->isPost() && $userForm->isValid($_POST)){
                        $data = $userForm->getValues();
                        //set up the authrisation adapter
                        //get the default database adapter
                        $db = Zend_Db_Table::getDefaultAdapter();
                        //creationg auth adapter
                        $authAdapter = new Zend_Auth_Adapter_DbTable($db,'users','password','email');
                        //setting username and password
                        $authAdapter->setIdentity($data['username']);
                        $authAdapter->setCredential(md5($data['password']));
                        //Authentication
                        $result = $authAdapter->authenticate();
                        if($result->isValid()){
                                //Storing firstname,lastname of user
                                $auth = Zend_Auth::getInstance();
                                $storage = $auth->getStorage();
                                $storage->write($authAdapter->getResultRowObject(
                                        array('fullname','username','email','dob','gender')));
                                        return $this->_forward('index');}
                        else{
                                $this->view->loginMessage = "Either Email-id or password incorrect!";
                                }
                }
                        $this->view->form->$userForm;
        }
               
       
               
}


?>

Reply | Threaded
Open this post in threaded view
|

Re: I am facing this error when i run query to databse

Marco Pivetta
I am really sorry to answer you this way, but it looks like you don't understand how Zend Framework's MVC works.
That return $this->_forward('list');  is like an internal redirect.
I suggest you a read of http://framework.zend.com/manual/en/learning.quickstart.intro.html :)
Marco Pivetta
http://twitter.com/Ocramius
http://marco-pivetta.com



On 12 November 2011 22:18, vindu525 [via Zend Framework Community] <[hidden email]> wrote:
Thank you Marco pivetta

The values are getting inserted into the database , but still i dont know why this error occuring

//complete controller


<?php

class SignupController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $auth = Zend_Auth::getInstance();
                if($auth->hasIdentity()){
                        $this->view->identity = $auth->getIdentity();
                        }
    }

    public function createAction()
    {
        $userForm = new Form_SignUpForm();
                if($this->_request->isPost())
                {
                        if($userForm->isValid($_POST))
                        {
                                $userModel = new Model_SignUpForm();
                                $userModel->createUser(
                                        $userForm->getValue('fullname'),
                                        $userForm->getValue('username'),
                                        $userForm->getValue('password'),
                                        $userForm->getValue('email'),
                                        $userForm->getValue('dob'),
                                        $userForm->getValue('gender')
                                );
                                return $this->_forward('list');
                        }
                }
                               
                $userForm->setAction('/LC_Case/public/signup/create');
                $this->view->form = $userForm;
    }
       
        public function loginAction()
        {
                $userForm = new Form_SignUpForm();
                $userForm->setAction('/LC_Case/public/signup/login');
                $userForm->removeElement('fullname');
                $userForm->removeElement('username');
                $userForm->removeElement('dob');
                $userForm->removeElement('gender');
                $this->view->form = $userForm;
               
                if($this->_request->isPost() && $userForm->isValid($_POST)){
                        $data = $userForm->getValues();
                        //set up the authrisation adapter
                        //get the default database adapter
                        $db = Zend_Db_Table::getDefaultAdapter();
                        //creationg auth adapter
                        $authAdapter = new Zend_Auth_Adapter_DbTable($db,'users','password','email');
                        //setting username and password
                        $authAdapter->setIdentity($data['username']);
                        $authAdapter->setCredential(md5($data['password']));
                        //Authentication
                        $result = $authAdapter->authenticate();
                        if($result->isValid()){
                                //Storing firstname,lastname of user
                                $auth = Zend_Auth::getInstance();
                                $storage = $auth->getStorage();
                                $storage->write($authAdapter->getResultRowObject(
                                        array('fullname','username','email','dob','gender')));
                                        return $this->_forward('index');}
                        else{
                                $this->view->loginMessage = "Either Email-id or password incorrect!";
                                }
                }
                        $this->view->form->$userForm;
        }
               
       
               
}


?>




If you reply to this email, your message will be added to the discussion below:
http://zend-framework-community.634137.n4.nabble.com/ZF2-Database-configuration-tp4033733p4035301.html
To unsubscribe from Zend Framework Community, click here.
See how NAML generates this email

Reply | Threaded
Open this post in threaded view
|

Re: I am facing this error when i run query to databse

intellix
I've just got into ZF1/2 and I still haven't found a top-down explanation of what ZF is doing in the background. Would be nice to have a diagram that says: This starts here, this calls this, this grabs the DI, this pulls in the dependencies then this gets the view parameters then this passes them to the template, then it's parsed here then its displayed!

I mean I know what MVC is but I have NO idea what's going on in the background. I think as soon as anyone finds out how to do anything in ZF they turn to consultancy to sell the information... then more people are suckered into using it through 'this is made by the devs of PHP' endorsement.

I've managed to get the ZF injecting stuff into the database and I think the best place to find your answer is in the Akrabat ZF2 tutorial (http://akrabat.com/getting-started-with-zend-framework-2/)

He basically declares the DB config, passes that to an adapter, passes the adapter to a table and then pass the table to the model or so... codes in there anyway.
Reply | Threaded
Open this post in threaded view
|

Re: I am facing this error when i run query to databse

weierophinney
Administrator
-- intellix <[hidden email]> wrote
(on Wednesday, 30 November 2011, 01:22 PM -0800):

> I've just got into ZF1/2 and I still haven't found a top-down explanation of
> what ZF is doing in the background. Would be nice to have a diagram that
> says: This starts here, this calls this, this grabs the DI, this pulls in
> the dependencies then this gets the view parameters then this passes them to
> the template, then it's parsed here then its displayed!
>
> I mean I know what MVC is but I have NO idea what's going on in the
> background. I think as soon as anyone finds out how to do anything in ZF
> they turn to consultancy to sell the information... then more people are
> suckered into using it through 'this is made by the devs of PHP'
> endorsement.

Listen, I know you're frustrated, but that's no reason to spin unfounded
conspiracy theories.

The fact is, ZF2 is still in fairly early stages of development, and the
MVC is changing every other week or so in some way or another. Ralph is
currently working on a proposal to make the DI/Service Locator story
simpler and easier to explain, which should help a fair bit.
Additionally, there's a lot of discussion happening on IRC and between
contributors to identify what works, what doesn't, and how to tell a
consistent and relatively simple story around the MVC.

Once we get some of these details ironed out, yes, I think a
diagram/flow chart is a great idea, to better show the various stages of
an application and how the parts interact.

> I've managed to get the ZF injecting stuff into the database and I think the
> best place to find your answer is in the Akrabat ZF2 tutorial
> (http://akrabat.com/getting-started-with-zend-framework-2/)

That's definitely a good one.

BTW, I collected a number of resources in a bit.ly bundle:

    http://bit.ly/rzOOge

If you come across other resources, let me know, and I'll add them to
that list.

> He basically declares the DB config, passes that to an adapter, passes the
> adapter to a table and then pass the table to the model or so... codes in
> there anyway.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]