We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Model Edit Template

I have 2 tables : Users and Projects and I use another table User_Proj which contains uID and ProjID to link the two tables.

I use Phalcon DevTool to generate CRUD for the three tables.

However, for the edit and search for the User_Proj, I would like to display User Name and Project Name instead of UID and ProjID in the edit and search pages.

How ?



43.9k
edited May '14

Hi,

define relations in your model declarations. Read this carefully https://docs.phalcon.io/en/latest/reference/models.html#defining-relationships



1.8k

Hi,

I've defined the link and used phalcon devTool to generate the various classes for the Users, Projects and UserProj.

So, I have

class Projects extends \Phalcon\Mvc\Model { .... .....

public function initialize()
{

$this->hasMany("projid", "UserProj", "projid", NULL); } }

class Users extends \Phalcon\Mvc\Model { .... .....

public function initialize()
{

$this->hasMany("uid", "UserProj", "uid", NULL); } }

class UserProj extends \Phalcon\Mvc\Model { ... ....

public function initialize()
{

$this->belongsTo("uid", "Users", "uid", array("foreignKey"=>true)); $this->belongsTo("projid", "Projects", "projid", array("foreignKey"=>true));

}

}

I have no idea to modify the user_proj templates like views\user_proj\edit.volt and search.volt, etc ...

I would like to have drop-down list for the user to be able to select the users to the project or project to the user instead of the user id and project id.

Sorry! I am new to the framework.

On Wed, May 7, 2014 at 4:56 AM, le51 [email protected] wrote:



43.9k

You're quiet there ! Now, in your view files you can use select tag:https://docs.phalcon.io/en/latest/reference/volt.html#using-tag-helpers

{{ select("project", Projects, 'using': ['id', 'name']) }}



1.8k

But it caused an error << Undefined variable : Projects in .....edit.volt

On Wed, May 7, 2014 at 8:15 PM, le51 [email protected] wrote:



1.8k

Can we use the UserProjController to pass the Users and Projects info into edit.volt

class UserProjController extends ControllerBase {

/**
 * Edits a user_proj
 *
 * @param string $id
 */
public function editAction($id)
{

        $parameters = $this->persistent->parameters;
        if (!is_array($parameters))
        {
            $parameters = array();
        }

        $users = Users::find();
        $projects = Projects::find();

        // how to carry on from here ?????

}

}

Please guide me !

Thanks!

On Thu, May 8, 2014 at 9:24 AM, Alex Toh [email protected] wrote:



1.8k

I did not figure out the correct way to pass the Users and Projects into the volts

But this is what i did,

<?php

$users = Users::find(); $projects = Projects::find();

?>

Anyone has a more proper way ????