我一直在使用Grocery Crud来开发一个简单的本地应用程序,该应用程序允许用户自己注册并对乐队进行评级并对其进行评级,并选择他们知道也在应用程序中注册的人。
实体:
人(person_id,person_URL,姓名,家乡)
带(band_id,band_URL,band_name,国家,流派)
关系:
喜欢(为person_id,band_id,率)
知道(为person_id,known_person_id)
我的问题是:
1)我想要返回一张人和知名人士的表格,如下所示:
KNOWS
person_id | fullname | known_person_id | known_fullname
但是我不能使用* set_relation_n_n * function'因为关系是(Person - > Likes - > Person),所以它给了我错误。我想出的另一个解决方案是创建一个自定义表,使查询返回我想要的值并在表中显示(下面的代码)。返回的自定义表是正确的,但当我将它呈现给我的Grocery Crud表时,我需要指定$ crud-> columns('person_id','fullname','known_person_id','fullname'),它无法区分该人的全名和已知人的全名。为了能够以这种方式显示表格,我该如何制作呢?
2)我在另一个表中遇到了同样的问题,但可以使用函数* set_relation_n_n *来管理它,因为它是一个关系(Person - > Likes - > Band),所以既然是2个不同的实体它没有给我一个错误。问题是查询(下面的代码)返回整个表格,我每页只需要25条记录。当我尝试在查询中使用“LIMIT 25”时,它只返回25条记录,“下一页”按钮不起作用。任何解决方案?
下面是所有信息:
问题1的代码:
function knows_management()
{
$crud = new grocery_CRUD();
$crud->set_model('model_socialnetwork');
$crud->set_table('knows');
$crud->set_subject('Known');
$crud->basic_model->set_query_str('SELECT tb1.person_id, tb1.fullname, tb1.known_person_id, person.fullname FROM (SELECT person.person_id, person.fullname, knows.known_person_id FROM person INNER JOIN knows ON person.person_id = knows.person_id) tb1 INNER JOIN person ON tb1.known_person_id = person.person_id');<br>
$crud->columns('person_id','fullname','known_person_id','fullname');
$output = $crud->render();
$this->_socialnetwork_output($output);
}
问题2的代码:
function likes_management()
{
$crud = new grocery_CRUD();
$crud->set_model('model_socialnetwork');
$crud->set_table('likes');
$crud->set_subject('Like');
$crud->columns('person_id','fullname','band_id','band_name', 'rate');
$crud->basic_model->set_query_str('SELECT tb2.person_id, tb2.fullname, tb2.band_id, band.band_name, tb2.rate FROM(SELECT tb1.person_id, person.fullname, tb1.band_id, tb1.rate FROM(SELECT person.person_id, likes.band_id, likes.rate FROM person INNER JOIN likes ON person.person_id = likes.person_id) tb1 INNER JOIN person ON tb1.person_id = person.person_id) tb2 INNER JOIN band ON tb2.band_id = band.band_id');
$output = $crud->render();
$this->_socialnetwork_output($output);
}
答案 0 :(得分:0)
问题1)如果在查询中使用别名,例如
,该怎么办?SELECT tb1.person_id,tb1.fullname as Tb1fullName,tb1.known_person_id,person.fullname as PersonFullName
问题2)我不建议您在查询中直接/手动添加LIMIT。在文件application / config / grocery_crud.php中,您有两个与分页直接相关的选项
您应该正确使用和配置它们
// The default per page when a user firstly see a list page
$config['grocery_crud_default_per_page'] = 25;
....
//Having some options at the list paging. This is the default one that all the websites are using.
//Make sure that the number of grocery_crud_default_per_page variable is included to this array.
$config['grocery_crud_paging_options'] = array('10','25','50','100');