Fatal error: Call to undefined function validation_errors() in - php

Here is the code:
class CCI extends Controller {
function CCI()
{
parent::Controller();
}
function index()
{
$this->load->helper('url');
$this->load->view('Users/login');
}
function test()
{
echo "Testing Data";
}
}
The page was loading fine until I moved the location of the "login" page inside of the "Users" folder

Well then probably change
$this->load->view('Users/login');
to
$this->load->view('login');
Since you moved the file inside the Users folder you need to adjust paths for that.

You're properly displaying any validation errors within your view using the 'validation_errors' function that's located in the 'form_helper'. Load the 'form_helper' as well and you should be fine.

Add following two lines of code to the controller:
$this->load->helper('form');
$this->load->library('form_validation');

Related

Laravel Controller and helper file: Undefined variable in view

I have an issue trying to use in my controller a function located in an helper file which is auto-loaded. I already used helper functions in some controllers but this function doesn't work and I don't understand why. I have different resources that use a similar code for the controller index() function for example. So my aim is to make functions that I can use in different controllers in this way.
Here's the error I get: "Undefined variable: articles" in the view file ArticlesIndex.blade.php
Helper function:
function res_index($collection,$viewName,$varName) {
if(!$collection->isEmpty()) {
$collection->take(10);
return view($viewName, compact($varName));
} else {
return 'Nothing';
}
}
And here's my index() function located in the controller:
public function index()
{
$articles = Article::all();
return res_index($articles,'ArticlesIndex','articles');
}
Thanks a lot !
Return value, returned by res_index:
return res_index($articles,'ArticlesIndex','articles');

Codeigniter not finding file url helper

So I have this setup:
ARTISTAS
But when I click on that link, it takes me to http://localhost/Universal%20Music/Universal/artistas/index which says 404, like if there's nothing there but I've already created the controller with that name loading some views in it. Am I missing something here?
EDIT
My config.php has:
$config['base_url'] = 'http://localhost/Universal/Universal';
I stop using spaces in the names of the folders and now the path is:
C:\Users\Horacio\Documents\Projects\Universal\Universal
The controller file has the same name of the class I need and the code inside is:
<?php
class Artistas extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index()
{
$this->load->view('header');
$this->load->view('main-index');
}
}

"Unable to load the requested file"

Using CodeIgniter 2.0.3 on XAMPP 1.7.7 I have code where I get the error as: Unable to load the requested file: home.php
The home.php code as follows stored in ./ci2/application/controllers:
class Home extends CI_Controller {
function Home()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
While using it just notice:
controller's name is home.php
File named home.php must be present in ci/views
Incase file extention in view folder is not php eg like its html.
then load it using : $this->load->view('home.html');
the function u need to call from outside must be public So make it:
public function index() {... }
as u are calling the constructor for the class Home. Call it like:
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home');
}
Now it will work !
Your call to $this->load->view('home'); will be looking for home.php in /ci2/application/views/. That's the file it can't find.
I'm assuming you're calling http://myapp/index.php/home/ - that means it'll automatically call the index() method.
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
}
Please check the name of the file you have created in application/views/, because otherwise the code is correct.

how to call a function inside a controller in opencart

i have a controller that have with in let's say thingy/stuff directory
<?php public function index() { /*thingy stuff */ }
public function anotherfunction() {/*other thingy stuff*/} ?>
i see tthe url like index.php?route=thingy/stuff&var=dd
what i want is to call an $.post to this function inside that controller
so it uses another template file thingy.tpl and return html to use
what the URL should like ??
i searched for hours ans it sounds like there is no development documentation for open-cart out there
let's say you have a controller called "stuff" under the thingy folder and a function called "my function" within that class, that looks like this:
class ControllerThingyStuff extends Controller {
public function index() {
// Some code
}
public function myfunction() {
// Your code
}
}
if you want to directly communicate with this function using the URL you can add the function name to the end of the route parameter "route=thingy/stuff/myfunction& ..." and load the thingy.tpl inside the function and return it after rendering:
// some code
$this->template = 'template/product/thingy.tpl';
...
$this->response->setOutput($this->render());
if are using the open cart 1.5 and you want to use jQuery AJAX with JSON then you'll need to import the JSON library before rendering:
$this->template = 'thingy/stuff/thingy.tpl';
$json['output'] = $this->render();
$this->load->library('json');
$this->response->setOutput(Json::encode($json));
take a look at the checkout page to get some ideas, the default open cart 1.5 template uses the same technique to load the templates for each section.
It's added to the route if it's not index, which it is by default, for example
<?php
class ControllerThingyStuff extends Controller {
public function index() {
// This is called with route=thingy/stuff or thingy/stuff/index
}
public function something() {
// This is called with route=thingy/stuff/something
}
}

Fatal error: Call to undefined function site_url()

I am using the CodeIgniter framework for PHP. I have created a view named "login.php". Once I
created the view, I then loaded the view inside of a function named "index" which is located
inside a class named "CCI" that extends the Controller but I keep receiving this error: Fatal
error: Call to undefined function site_url() in C:\wamp\www\FinalP_CCI_Clone\system
\application\views\login.php on line 12. I don't understand the issue I an having because the
welcome page loads fine and my second function inside of the "CCI" class loads fine as well.
Here is some of the code:
Controller Files:
function CCI()
{
parent::Controller();
}
function index()
{
$this->load->view('login');
}
function test()
{
echo "Testing Data";
}
}
/* End of file login.php /
/ Location: ./system/application/controllers/cci.php */
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$this->load->view('welcome_message');
}
function test()
{
echo "Testing Data";
}
}
/* End of file welcome.php /
/ Location: ./system/application/controllers/welcome.php */
You have to load the helper. The function site_url() is provided by the url helper, as described here.
$this->load->helper('url');
You can try this:
First Load the URL Helper with:
$this->load->helper('url'); or set the following value in application/config/autoload.php
$autoload['helper'] = array('url');
Then you can show the site url with:
base_url() (result: http://example.com/) or
site_url() (result: http://example.com/index.php/)
Note: Results depends on values stored in application/config/config.php

Categories