我正在codeigniter上做一些练习来从数据库中检索数据,我很成功.但是当我想获取特定字段的数据时会出现问题.检索我在本地主机上使用以下URL的特定值:
localhost/codeigniter/index.php/news/view/city-news
Run Code Online (Sandbox Code Playgroud)
新闻是控制器,视图是控制器的方法,城市新闻是参数.
这是我的控制器代码:
public function view($slug)
{
$data['news'] = $this->news_model->get_news($slug);//here i am getting the slug value.
if (empty($data['news_item']))
{
show_404();
}
$data['title'] = $data['news_item']['title'];
$this->load->view('templates/header', $data);
$this->load->view('news/view', $data);
$this->load->view('templates/footer');
}
Run Code Online (Sandbox Code Playgroud)
这个方法调用模型news_model的方法get_news($ slug).这个方法的代码是:
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}
echo $slug;//here is i m also getting the slug value.
$query = $this->db->get_where('news', array('slug' => $slug));//i think this is not working properly
print_r($query->row_array());die;//now i am getting values here.
return …Run Code Online (Sandbox Code Playgroud) 可能重复:
PHP中完全面向对象的框架
我对CodeIgniter一件事情感到沮丧,你既不能扩展控制器也不能扩展模型.我知道你可以用mod做HMVC,这有点给你继承能力,但我对此并不满意.是否存在面向对象的PHP MVC框架,基本上允许扩展控制器,模型?
我在使用codeigniter时遇到了一些问题,它只是让我加载索引方法而不是任何其他函数:
我的代码:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Private_page extends CI_Controller
{
function __construct()
{
parent::__construct();
if($this->session->userdata('paramID') === false) {
redirect('/public');
}
}
public function index()
{
/* Header Data */
$data = array(
'title' => 'Bizispace Private Page',
'paramID' => $this->session->userdata('paramID')
);
// Load Header
$this->load->view('template/header.php', $data);
/* Get Subcriptions Details */
$this->load->view('private/index.php', $data);
$this->load->view('template/footer.php');
}
public function logout()
{
$this->session->sess_destroy();
redirct('public_page');
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我有一个路线设置:
$route['private'] = "private/private_page";
Run Code Online (Sandbox Code Playgroud)
然后我运行:/index.php/private/它显示索引页面很好,但如果我运行/index.php/private/logout我得到:
"无法加载默认控制器.请确保Routes.php文件中指定的控制器有效."
编辑*我在32位Windows 7上运行WAMP
难道我做错了什么?
这是我想要做的:
$newArray = array();
foreach($student as $s){
$newArray[$s->id][$s->grade] = $s;
}
Run Code Online (Sandbox Code Playgroud)
我想按照他们的成绩对学生进行排序(更多的是一组而不是一种类型),但我只想要将成绩分类而不是id.我可以不这样做:
$newArray[$s->id] = $s->grade
asort($newArray)
Run Code Online (Sandbox Code Playgroud)
但是我需要剩下的数据$s.此外,我希望维护每个学生的大量数据.
我怎样才能实现这样的排序?
我当前的查询显示从指定时间发布在我的墙上的一些消息.
$fql = "SELECT post_id, actor_id, target_id, message FROM " .
"stream WHERE filter_key = 'others' AND created_time > 1346277600 LIMIT 50";
Run Code Online (Sandbox Code Playgroud)
问题是,它只显示uid而不是在我的墙上发布消息的人的实际名称.
编辑:我现在使用multiquery
$fql = "{" .
"\"user_stream\" : \"SELECT post_id, actor_id, target_id, message FROM stream WHERE " .
" filter_key = 'others' AND created_time > 1346277600 LIMIT 50 \"" .
"\"actor_info\" : \"SELECT uid, name FROM user " .
" WHERE uid IN (SELECT actor_id, target_id FROM #user_stream)\"" .
"}";
$data['msgs'] = $this->facebook->api(array(
'method' => 'fql.multiquery',
'queries' => …Run Code Online (Sandbox Code Playgroud) 我在我的静态函数中尝试调用CodeIgniter方法时遇到了麻烦,只是使用$这不起作用,因为它不在对象上下文中,静态关键字也不起作用.这是我的核心模型中的代码示例,$ table变量是从另一个模型(如posts)成功定义的.
class MY_Model extends CI_Model {
protected static $table;
public function __construct() {
parent::__construct();
}
public static function find_all() {
$this->db->select('*');
$sql = $this->db->get(static::$table);
return $sql->result();
}
}
Run Code Online (Sandbox Code Playgroud) 在我的项目中,用户将通过粘贴来自其他站点的URL来上传视频.我尝试了嵌入但不能正常工作,因为它为特定网站,YouTube等提供嵌入式代码.我想完全像这个网站http://www.myvidster.com/.我尝试使用cURL代码: -
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $video_url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_VERBOSE, true); // Display communication with server
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json_reply = curl_exec($ch);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)
和代码file_get_contents是:
$video_url = $_POST['video_url'];
$html = file_get_contents($video_url,true);
Run Code Online (Sandbox Code Playgroud)
但是使用curl我也只获得了一些网站的HTML部分.我试了一个星期,但仍然没有结果.是否可以从每个站点获取嵌入的视频代码?或者我做错了什么?
嗨,我的数据库查询有问题.
$q = $this->db->query("SELECT * FROM (`knihy`)
WHERE `stav` = 1
AND (Autor1 LIKE '$vyraz'
OR Autor2 LIKE '$vyraz'
OR Autor3 LIKE '$vyraz'
OR Autor4 LIKE '$vyraz')
ORDER BY `id` desc LIMIT $limit OFFSET $offset ");
Run Code Online (Sandbox Code Playgroud)
问题在于,当我搜索"lorem"的例子时,我在我的表中例如在行Autor1内容中:"lorem ipsum"将找不到任何内容.但如果我正在寻找lorem ipsum,那么就会找到那个领域.请问哪里有问题?
这就是我理解Codeigniter目录结构的操作方式.我正在使用Codeigniter 2.1.2.我误解了每个目录的用途吗?我忘记了什么?
-+ /application/
|
|-+ /cache/ Used for caching pages if it is enabled
|-+ /config/ Contains the configuration files for this project
|-+ /controllers/ All of your controllers are saved here
|-+ /core/ Used for modifying the core Codeigniter classes
|-+ /errors/ Handles your errors and their output
|-+ /helpers/ Contains your own functions
|-+ /hooks/ Used for running code at the certain points in the routing process
|-+ /language/ Occasionally used for translating parts of your project …Run Code Online (Sandbox Code Playgroud) 我的Codegniter应用程序结构是
- root
---- application
---- system
---- includes
---- .htaccess
---- index.php
Run Code Online (Sandbox Code Playgroud)
我会让所有人都可以访问"包含"文件夹,事实上我的文件夹/包含是不可能的.只有我的index.php是可访问的.我想只允许所有子目录访问"包含"目录.
这是我的htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the …Run Code Online (Sandbox Code Playgroud)