使锚加载页面包含数据库中引用行的数据
我正在尝试总体学习代码点火器库和面向对象的 PHP,并且有一个问题。
我已经制作了一个从数据库加载所有行的页面,在其中,我回显了一个锚标记,该标记是指向以下结构的链接。
echo anchor("videos/video/$row->video_id", $row->video_title);
所以,我有一个名为 Videos 的类,它扩展了控制器,在该类中有索引和视频,它们被正确调用(当您单击视频标题时,它会将您发送到视频/视频/5,例如,5 是我正在使用的表的主键。
所以基本上我要做的就是将 5 传递回控制器,然后让特定的视频页面从视频表中输出特定的行数据。我的视频控制器看起来像这样:
function video()
{
$data['main_content'] = 'video';
$data['video_title'] = 'test';
$this->load->view('includes/template', $data);
}
所以,基本上 test 应该是 test 而不是 test,它是一个查询的返回值,它表示获取表“videos”,即带有 video_id
的行>“5”,并使$data['video_title']
等于数据库中video_title
的值...
现在应该已经弄清楚了,但是不要,任何帮助将不胜感激!
I'm trying to learn the code igniter library and object oriented PHP in general and have a question.
I've gotten as far as making a page which loads all of the rows from my database and in there, I'm echoing an anchor tag which is a link to the following structure.
echo anchor("videos/video/$row->video_id", $row->video_title);
So, I have a class called Videos which extends the controller, within that class there is index and video, which is being called correctly (when you click on the video title, it sends you to videos/video/5 for example, 5 being the primary key of the table I'm working with.
So basically all I'm trying to do is pass that 5 back to the controller, and then have the particular video page output the particular rows data from the videos table. My function in my controller for video looks like this:
function video()
{
$data['main_content'] = 'video';
$data['video_title'] = 'test';
$this->load->view('includes/template', $data);
}
So ya, basically test should be instead of test, a returned value of a query which says get in the table "videos", the row with the video_id
of "5"
, and make $data['video_title']
equal to value of video_title
in database...
Should have this figured out by now but don't, any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道我是否太晚了,但这也许可以解决你的问题......
将其放入您的 video() 函数中
,然后放入您的 video_view 文件中...
这是一个很好的资源: http://codeigniter.com/user_guide/database/index.html
希望有帮助...
请有人编辑这个问题,因为它太难读了......
I don't know if I'm too late but maybe this can solve your problem...
put this in your video() function
and then that in your video_view file...
this is a good resource: http://codeigniter.com/user_guide/database/index.html
hope that helps...
and please someone edit the question because it's too hard to read...
您需要的是了解 URI 类 的工作原理
基本上:
然后是类似的内容
What you need is to understand how the URI Class works
Basically:
and then something like
您可以使用 URI 类,也可以执行以下操作:
换句话说,使用扩展 Controller 的类内的函数,您可以向这些函数添加参数,CI 将自动传入 URI 项以传递给这些参数。
You could use the URI Class, or you can do the following:
In other words, with functions inside classes that extend Controller, you can add parameters to those functions and CI will automatically pass in the URI items in order to those parameters.