cakephp $this->User->find('all'); - php

Im totally new to cakephp and done some beginners tutorial and I see this line of code:
$this->User->find('all');
My question is this, where did 'User' come from since Ive never declared it on the program and I did not return an error but when I change the name of that, a bunch o errors happen.
Anyone pls help.

Go through the model documentation here http://book.cakephp.org/1.3/en/The-Manual/Developing-with-CakePHP/Models.html .
User is Model class in app/model folder.If you didnot created that ,cakephp will do it itself by default

Related

Learing laravel and have problem with getURLList();

Im trying to learn Laravel framework and having trouble with getURLList();
In the tutorial that im following it says.
class StudInsertController extends Controller
{
public function insert(){
$urlData = getURLList();
return view('stud_create');
}
But the getURLLIST(); comes back as
Call to undefined function App\Http\Controllers\getURLList()
And i dont find any information about that.
Is it because the tutorial is for older version of Laravel?
The link to the tutorial itself is here:
https://www.studentstutorial.com/laravel/insert-data-laravel
Can somebody point me in the right direction.
I would have written this as a comment, but I don't have enough reputation.
From what the tutorials says, there are just a few files that you need to touch which effectly means they are not adding a custom helper method.
After looking at the code, I don't see any use for the line of code getting the URLs. It would have been useful if you were to pass the data forward to your view.
So I would recommend you remove the line $urlData = getURLList();. It should work just fine. I don't know if the author left it there by error.

Error when loading library even library loaded

I'm now updating my company's old CI2 Website to CI3. Model, Controller and View from the CI2 seem to work fine after a little bit changes but my app keep showing "Fatal error: Class 'CI_Func' not found in pathtoapp\system\core\Common.php on line 196" when load library, the "Func.php" with "F" is capitalization, it's location is in "pathtoapp\application\libraries" and just echo "Hello world" for testing purpose. The text "Hello world" showing up but the app still showing the error. I've tried many other libraries but it just showing the same kind of error like "Fatal error: Class 'CI_Someotherlibrary'...". My system is running using IIS, PHP 5.5 and MySQL.
Here is my Func.php and my controller
defined('BASEPATH') OR exit('No direct script access allowed');
class Func {
function __construct()
{
echo 'Hello world';
}
}
class Home extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->library('form_validation');
$this->load->helper(array('url', 'form', 'download', 'text', 'views'));
$this->load->library('pagination');
$this->load->Model("Menus");
$this->load->Model("2019/News","News");
$this->load->library('Func');
}}
I don't know why it keep adding "CI_" before my library name. I'm still new with CI and new to stackoverflow too. I've already search over internet and try almost everything but still no luck. Any advice will be appreciated. Thanks in advance.
PS: Sorry for my bad English.
update infomation from #Bira quest
- When i change the name of class to CI_Func or $this->load->library('func');, the new error coming up: "An Error Was Encountered Unable to load the requested class: Func"
Update 1:
Here is two threads that nearly like my issue but can't solve my problem
Thread 1
Thread 2
Update 2:
- I figured it out that when i'm not using $this->load->view in my Views, the error disappear. May be the cause is $this->load->view trigger something that make loader class went wrong. I just don't know what wrong with it because i'm using $this->load->view to load some part of my website layout and it worked fine with CI2. Someone help me, please.
Update 3:
- I've solved it. In my view, i create new instance of the controller using like $home = new home(); so may be it load the library again and cause the error. Thank you all for your helps.
I've solved it. In my view, i create new instance of the controller using like $home = new home(); so may be it load the library again and cause the error. It's hard to trace the error. Thank you all for your helps.

Ion auth Codeigniter Login throwing errors after logging in

This is my first project using both Codeigniter and Ion Auth and I've finished this tutorial: http://www.rappasoft.com/tutorials/view/5#.U1bJLeZdWpo
But now that I've reached the end, I have an error that is appearing when all of my code looks identical to the tutorial. The error is:
Message: Creating default object from empty value
Filename: core/MY_Controller.php
Line Number: 13
But the odd thing is that the code from the MY_Controller file is copied right from the tutorial. Here's the code I have:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
public function __construct() {
parent::__construct();
if (!$this->ion_auth->is_admin()) {
redirect('auth/login');
} else {
//Store user in $data
$data->user_info = $this->ion_auth->user()->row();
//Load $the_user in all views
$this->load->vars($data);
}
}
}
?>
The correct view loads underneath the error but obviously I'd like to know what's wrong. Since this is my first turn time working with ion-auth and I'm relatively new to code igniter as well, I was wondering if anyone knew how to go about debugging an error like this. Teach a man to fish, feed him for a lifetime! I'd really appreciate not just solutions but methods so I can learn and do this on my own.
Are you working on PHP 5.4+ ?
In that case, you must declare $data before using it:
Change:
$data->user_info = $this->ion_auth->user()->row();
to
$data = new stdClass();
$data->user_info = $this->ion_auth->user()->row();
and try again. Hpe it helps!
I think I might have figured it out. I think the issue might be that the default login information (the ones provided by ion auth) do not have any additional information in the database. This means that when the $data variable goes to set the additional account information, it doesn't find anything. It's not a strong enough error to crash the page but it is warning me that there is no other account information available even though it is supposed to be looking for more info.
So how to fix this? Create a user for testing purposes with a full compliment of account information and see if that solves the problem. The only problem is that I don't know how to add new users using ion auth and my views aren't sophisticated enough yet to make that process easy.
I've looked at the create_user() method in the auth.php file but when you press submit after filling out the form, it kicks you back to the same page with all the info. I have a feeling an edit needs to be done here although I don't quite know what to change. I've been looking on the ion auth documentation but it seems a bit... sparse. I think I'm on the right track although I'd really like to hear if someone else has a better explanation or solution. As of now, I haven't actually fixed it yet. Just deduction.

Call to undefined method ActiveRecord\Config::initialise() composer

Hey everyone I'm following a tutorial on Composer, I've installed ActiveRecord and I'm trying to create a database model. Whenever I load the page though I get this error: Call to undefined method ActiveRecord\Config::initialise()
Here's my setup file in index.php
require_once "vendor/php-activerecord/php-activerecord/ActiveRecord.php";
ActiveRecord\Config::initialise(function($cfg) {
//setting up a model (which is the representation of a table)
$cfg->set_model_directory('models');
$cfg->set_connections(array(
'development' => 'mysql://root:tutsplus#localhost/blog'
));
});
$posts = Post::all();
print_r($posts);
?>
And here's where I declare Post
class Post extends ActiveRecord\Model{}
I really cannot find the reason this isn't working, I actually did this instead to see if manually creating a new Post instance would fix the initialisation problem but it didn't, it had exactly the same error:
$post_class = new Post;
$posts = $post_class->all();
print_r($posts);
I'm really stumped on this one, I've usually managed to find something that fixes my problem on here but this is just nope. There is literally no difference to the tutorial code that I can see and I've checked it loads of times. Any help would be greatly appreciated.
(edit: the duplicate php-activerecord folders at the top isn't a code problem, the folder is actually duplicated and I haven't got round to moving the contents yet)
Point one: When using Composer, you are supposed to only include "vendor/autoload.php", and nothing else. Composer does the rest of autoloading for you.
Point two: It is called initialize with a Z, not S. You might simply have misspelled that method name.

CakePHP Facebook integration tutorial "Fatal error: Call to a member function share() on a non-object" [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Call to a member function on a non-object
I'm doing this tutorial here:
http://tv.cakephp.org/video/webtechnick/2011/01/12/nick_baker_--_facebook_integration_with_cakephp
I baked a new project with cake bake facebook_app and set the configuration database file to the correct settings and the default cakePHP screen showed that tmp directory was writable, DB setup was good, etc.
I downloaded the CakePHP plugin by WebTechNick here: https://github.com/webtechnick/CakePHP-Facebook-Plugin, and filled out app information (app_secret, app_id, etc), adding it to facebook_app/config/facebook.php
Changed facebook_app/app_controller.php:
class AppController extends Controller {
var $name = 'Facebook';
var $helpers = array('Session', 'Facebook.Facebook');
}
Then just exactly as in the tutorial `facebook_app/views/pages/home.ctp':
<h1>Facebook_App</h1>
<?php $this->Facebook->share(); ?>
returning the error message:
Undefined property: View::$Facebook
I realize that means PHP didn't recognize Facebook as an object. But I installed the plugin!
Also, it seems not MVCish to have something like $this->Facebook->share(); in a view (home.ctp). However, this is exactly how WebTechNick does it in his tutorial (I followed it exactly 3x) and it does not work for me. I'm a complete noob at cakePHP (although I've read the entire documentation) and I'm just trying to learn and understand through examples.
:) To be fair, it's PHP - you didn't install anything. Or if you prefer, "install" != "invoke." PHP is really amazingly easy to debug. I mean, it tells you exactly what's wrong:
Like turning to a channel that's not on the air, the error your getting means that the object you're calling doesn't actually exist, at least not in the scope you're trying to invoke it.
Is that your IDE? Is it set up for your Cake app? Are you sure the instructions were to set your AppController's $name to 'Facebook' instead of $name = Facebook_App in your AppController? It looks like you either replaced your actual app's AppController with the plugin files instead of putting them in the proper directory, or the plugin is not deferring / calling / extending / returning to the application the way it's supposed to. Knee jerk -> typo, naming conflict, path problem, permissions.
Cake's not even rendering. I can tell because your screenshot would show that error with the styled Cake errors. That tells you it's erroring before AppController class makes it to View class.
Create an instance of the Facebook object statically in the view and see what happens. Then, what does
function beforeFilter() {
parent::__construct() ?
}
get you? Anything? What about debug(), var_dump, the object functions will also shed light on what's happening. So will your logfiles.
Btw, if you don't use them already: Firefox + FirePHP + Xdebug = made of win.
I was having this problem and I found that the plugin I was using was for CakePHP 1.3 and I was using Cake 2.0. I found the BETA branch for the upgraded Cake 2.0 and it worked perfect.
Here is the Cake 2.0 BETA Branch

Categories