codeigniter

How to access variables from other methods inside the same class in PHP?

馋奶兔 提交于 2019-12-24 11:15:22
问题 I tried this but couldn't get it to work: class Profile extends CI_Controller { public function index() { $foo = 'bar'; } public function form_submit() { echo $this->index()->foo; } } I know I can make a variable accessible to all the methods in a class by declaring it outside all the methods at class level and declaring it as public. But here I need to declare the variable inside one of the methods. 回答1: If you are declaring it inside the method, you are out of luck unless you return the

Codeigniter failed to open stream permission when upload images

陌路散爱 提交于 2019-12-24 11:14:47
问题 Code: $filename = '12345.jpeg'; $source = imagecreatefromstring($imageData); $imageSave = imagejpeg($source,$filename,100); imagedestroy($source); $this->ftp->connect(); $this->ftp->upload($imageSave,'/public_ftp/incoming/'.$filename,'ascii', 0775); $this->ftp->close(); Error: Codeigniter failed to open stream permission when upload images. 回答1: Probably it is a permissions issue. Try this: sudo chmod -R 777 path/to/public_ftp/incoming/ However, this will give permission to everyone. For

Issue in creating datatable with codeigniter

有些话、适合烂在心里 提交于 2019-12-24 11:08:20
问题 I am trying to create Datatable with CodeIgniter using these files. In data.php(controller) which I've renamed to datatable.php I added "$this->getTable();" in function index() and only defined $aColumns and $sTable according to my need. No other changes are made. I run the code using this URL : "localhost/codeigniter/index.php/datatable" I am new to this so still not removed the index.php and I don't use base_url so I accordingly made changes in index.php while loading scripts and css. Also

SELECT MAX query returns only 1 variable + codeigniter

妖精的绣舞 提交于 2019-12-24 11:07:46
问题 I use codeigniter and have an issue about SELECT MAX ... I couldnot find any solution at google search... it looks like it returns only id :/ it's giving error for other columns of table :/ Appreciate helps, thanks! Model: function get_default() { $this->db->select_max('id'); $query = $this->db->getwhere('gallery', array('cat' => "1")); if($query->num_rows() > 0) { return $query->row_array(); //return the row as an associative array } } Controller: $default_img = $this->blabla_model->get

Codeigniter real_escape_string function can't call

孤者浪人 提交于 2019-12-24 10:58:27
问题 I have added the line below from my models $this->db->close(); And then this code gives me an error Severity: error --> Exception: Call to a member function real_escape_string() on boolean Any advice or suggestion would be appreciated. UPDATE: Here are the configs I use. Main DB connection $db['default'] = array( 'dsn' => '', 'hostname' => 'is my host address', 'username' => 'is my id', 'password' => 'is my password', 'database' => 'is my database name', 'dbdriver' => 'mysqli', 'dbprefix' =>

Ended up with an Object, how do I work with this?

依然范特西╮ 提交于 2019-12-24 10:57:34
问题 After solving part of my problem over here, I realized that I could get the data into the view, but then I had another problem. (controller) $this->load->model('testing/test_v_to_m_model'); $data['mydata'] = $this->test_v_to_m_model->display_character_info(); $this->load->view('testing/test_v_to_m_view', $data); (model) $query = $this->doctrine->em->createQuery("select u from ORM\Dynasties2\Characters u"); return $query->getResult(); (view) foreach ($mydata as $key => $row) { print_r($row); }

how to integrate twitter login and facebook login in a web site using codeigniter?

被刻印的时光 ゝ 提交于 2019-12-24 10:53:12
问题 I have already used twitter oauth and facebook library to login to my website.It works fine before now it is not working :(.I have debug the code and got to know that twitter access token and secret is not returning.For facebook login it also didnt get user id.pls help 回答1: Step 1: Download facebook library.https://github.com/facebook/facebook-php-sdk/tree/master/src Step 2: Upload it in \application\libraries Step 3:Create a facebook application.You wil get appId and secretcode.Paste the

Please help me setting up codeigniter and phpunit

笑着哭i 提交于 2019-12-24 10:52:04
问题 I have created few simple apps in codeigniter never tested it. Can anyone give me some links or explain how to setup codeigniter with phpunit ? Many thanks 回答1: This ciunit fork works well and it is compatible with the latest CI 2.1 https://bitbucket.org/kenjis/my-ciunit 回答2: http://www.knollet.com/foostack/ 来源: https://stackoverflow.com/questions/3497896/please-help-me-setting-up-codeigniter-and-phpunit

CodeIgniter passing data to the view

巧了我就是萌 提交于 2019-12-24 10:49:06
问题 I am trying to pass from my controller to the view like so... public function playerslist() { $this->load->database(); $data = $this->db->get('skaters'); $this->load->helper('url'); $this->load->view('playerslist', $data); } and in my view... <?php echo $data; ?> but I get this error... A PHP Error was encountered Severity: Notice Message: Undefined variable: data Filename: views/playerslist.php Line Number: 76 What am I doing wrong? What I would like to do with this data is put in a foreach

Capturing unexpected termination in PHP / CodeIgniter

我怕爱的太早我们不能终老 提交于 2019-12-24 10:48:10
问题 I'm using CodeIgniter to host a RESTful API and I'd like to capture any API response that does not return an expected status code. This is probably most easily explained with an example. In general, my code looks like this: function post_comment() { $comment = $_POST['comment']; $result = do_something_with_comment($comment); if ($result === true) { return_json_response(200, 'OK!'); } else { return_json_response(400, 'Something terrible happened...'); } } Returning either a 200 or 400 is