could not connect to database in codeigniter - codeigniter-2

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Home::$db
Filename: core/Model.php
Line Number: 51
updating autoload.php giving http:500 error

You have to load the db library first. In
autoload.php :
$autoload[‘libraries’] = array(‘database’);

It could be any the following:
You must make sure you have set up your database details correctly in the application/config/database.php file. Instruction on what to fill in here are explained on this page of the manual: http://codeigniter.com/user_guide/database/configuration.html
Or it could be that you first need to load the database library by writing the following code above where you have written your query:
$this->load->database();
And to run your query, the code should look roughly like:
$this->db->query('SELECT * FROM mytable');

you must go to autoload and replace $autoload['libraries'] with this $autoload['libraries'] = array('database', 'form_validation');

the guide says:
You can tell the model loading function to auto-connect by passing
TRUE (boolean) via the third parameter, and connectivity settings, as
defined in your database config file will be used:
$this->load->model('model_name', 'model_alias', TRUE);
and you can access the model by its alias like this:
$this->model_alias->method();
or without alias:
$this->load->model('model_name', '', TRUE);
and access the model:
$this->model_name->method();

Related

Laravel - How to clear config:cache on each request

I am working on a project which will have 50 subdomains and I found a solution to load separate .env file based on a domain name and everything is working fine... now my problem is
I have to run command config:cache to clear the cache so sytem can load relevant .env file, otherwise, it keeps loading the older .env file. How can i ask system to do cache clear on each load in bootstrap/app.php file???
My Code to load .env files in bootstrap/app.php
$domain = '';
if(isset($_SERVER['HTTP_HOST']) && !empty($_SERVER['HTTP_HOST'])){
$domain = $_SERVER['HTTP_HOST'];
}
if ($domain) {
$dotenv = \Dotenv\Dotenv::create(base_path(), '.env.'.$domain.'.env');
try {
$dotenv->overload();
} catch (\Dotenv\Exception\InvalidPathException $e) {
// No custom .env file found for this domain
}
}
I would advise against doing that because things WILL break.
However, to answer your question, you can use Artisan::call('config:clear') inside a middleware that you can call on each request.
But instead of doing that, you could build a middleware that detects the subdomain you're getting the request from and then call the command instead, just to avoid that extra load.
I used another way to solve this on my project. It is setting the config dynamically according to the request. The config is only valid for the current request. If the count of the dynamic config is less you can use
Config::set('myConfig.hostName', $hostName);
Before doing that you must use the package
use Illuminate\Support\Facades\Config;

Symfony2 - doctrine:generate:entity throws 'Bundle "AcmeBlogBundle" does not exist' error

I am trying to generate CRUD using command line in Symfony3 I am getting error as below
I tried clearing cache using below command line
php bin/console cache:clear
Still I am getting this error.
You need to generate/create the bundle AcmeBlogBundle first and add the bundle to the kernel in app/AppKernel.php.
Otherwise Doctrine doesn't know about the alias AcmeBlogBundle: that is used to resolve the class to an entity. Doctrine can't resolve the alias to an existing namespace and doesn't know where to put the Entity class.
Run the following command to create i.e. the AcmeBlogBundle bundle.
app/console generate:bundle --namespace=Acme\Bundle\AcmeBlogBundle
Your AppKernel.php should now contain the line:
public function registerBundles()
{
$bundles = array(
// ...
new Acme\Bundle\AcmeBlogBundle(),
);
// ...
return $bundles;
Afterwards the error message will be gone and you'll be able to generate your Entity with:
app/console doctrine:generate:crud --entity=AcmeBlogBundle:Entity

Laravel new command error

I did the following commands:
composer global require "laravel/installer=~1.1"
and
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
But when I try to do:
laravel new blog
I get the following error:
Notice: Undefined variable: output in C:\Users\****\AooDara\Roaming\Composer\vendor\laravel\installer\src\NewCommand.php on line 55
Fatal error: Call to a member function writeln() on null in C:\Users\****\AooDara\Roaming\Composer\vendor\laravel\installer\src\NewCommand.php on line 55
Any idea of what went wrong?
Seems like you already have a directory called 'blog' in your application directory. Try creating a laravel app with different name or delete / rename existing 'blog' directory and try again.
for example laravel new helloapp.
However, I think the error showing at the console is a bug of laravel new command. I could see the error at the console when I tried to create a app with same name again from same directory.
The error not exists now. Try creating other application.

set_flashdata() triggers a fatal error in PyroCMS

I moved a Pyrocms site to another server.
Go to index: blank page.
Turn on errors: get this
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Pages::$session
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function set_flashdata() on a non-object in /var/www/vhosts/brokentalkers.com/httpdocs/system/pyrocms/modules/modules/models/module_m.php on line 193
If it sheds any light, I made a tar.gz of the contents of the old httpdocs folder, and extracted it in the new httpdocs folder.
I made a duplicate of the database with an identical user, so config/database.php shouldn't need changing.
Any ideas? Thanks in advance.
It seems like $session class is not initializing correctly.
Check for default_ci_sessions table, if you are using sessions for database.
Check if the constructor is loading sessions library.
Check if session is in autoload.php config

codeigniter calling show_error from a library

I can't manage to call show_error from inside a library file I get
Warning: include(application/errors/error_php.php) [function.include]: failed to open stream: No such file or directory in E:\project\SOURCE\system\core\Exceptions.php on line 167
Perhaps you need to create a CI instance?
To access CodeIgniter's native resources within your library use the get_instance() function. This function returns the CodeIgniter super object.
more here
So perhaps something like
$CI =& get_instance();
$CI->show_error('something is not right here . . . ');
Will do what you want.

Resources