Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14353 articles
Browse latest View live

Getting a blank page

$
0
0
Hi All.

I am a noob at CI, have now worked my way fixing all errors etc, got my "hello world" to work, so th CI is there and working. and off course the index.php file is loading honkey-dori

My problem seems to be DB connection, or I am not sure.....

been testing with the examples from formget.com

insert-data-into-database-using-codeigniter
update-data-in-database-using-codeigniter
delete-data-from-database-using-codeigniter

At first i got some errors, that i fixed, but now when i go to display page (for the above mentioned)
localhost/myDir/index.php/..........

i only get a blank white page, the title is loaded as i can see the text at the top.....  but nothing else
checked and added database to autoload...


Any suggestions on how to get it to work........

404 - File Not Found Codeigniter 4

$
0
0
Hello there, I'm Crevitz. I'm quite new when it comes to codeigniter 4 and installed it using composer. When I run the spark and access via localhost:8080/myproject, this "404 File Not Found. Sorry! Cannot seem to find the page you were looking for" page.

I thought I did a mistake while installing codeigniter so I redo the installation also I recheck my php version which turns out to be 7.2.10
I also create htaccess in my project folder but it makes no difference.

I'm in lost, would somebody kindly help me?

PS: Is it gonna be different if you use --no-dev or just plain appstarter myproject?

Form-Action Variables not working while routing

$
0
0
Hi everyone,
it looks like my CI4 does not process form variables.

I have a very simple form with an action to "/login/" for example.

goes like this:
helper(['form', 'url']);
echo form_open('/login/user_login_process/');
echo form_input("eingabezeile", "eingabezeile");
echo form_close();

If I push the form button, the form fields are not available in the action-controller.
In my action-controller it allways says:
echo $_SERVER['REQUEST_METHOD']; --> "get".
And none of these work: $variable = $this->request->getPost("formfieldname"); doesnt give the value I entered.

I dont see the forest in front of the trees, as we say in german...

Thanks for a tip!
ME.

Get / delete all cache starting with prefix

$
0
0
Hey,

I'm working on a project that relies heavily on cache for performance gains. All the cache created is intentionally set to expire in a DECADE and deleted upon user/system action. When there are a few cache keys to handle with a few dependencies between the cached objects, there is no problem... Although, the more cache keys and dependencies there are to handle, the harder it gets to manage it and at some point, it creates inevitable bugs.

CodeIgniter offers some basic ways to get and delete single cache objects when the key is known (https://codeigniter4.github.io/userguide...ching.html).
--> Regarding the project I'm working on, the cache I create is named manually with some identifiers from the database to ensure unique cache keys. So, the hassle comes when wanting to delete it as I need to get the identifier back from the database.

A solution to this would be to add a method to find or delete all cache of which keys are starting with a given prefix.

PHP Code:
// find all cache starting with `prefix_`
cache()->findAll("prefix_*");
// would return an array: ["prefix_...", "prefix..."];

// delete all cache starting with `prefix_`
cache()->deleteAll("prefix_*"); 

I've seen that there is a `$prefix`attribute that can be set to prefix any created cache key, it could be merged somehow with the `clean()` method that removes the entire cache.

PHP Code:
// This would remove all the cache starting with "prefix"
cache()->prefix("prefix")->clean(); 

This would help greatly remove the load on the database (in my case) as well as maintaining cache more easily.

That's it, hope to have been clear!

PS: I've been using CodeIgniter4 for a few months now and I'm quite fond of it! Thanks for all your work.

RESTful Sub Resource Handling Url

$
0
0
hi  let jump in the  problem 
 i m  writing  Restful Api beck end  With Ci4 
if have two controller extend from ResourceController contact And ContactFile

how manger URL for sub Resuoures 

http://api.example.com/contact /* get*/ 
http://api.example.com/contact /* post*/  
http://api.example.com/contact/{id} /* put*/
http://api.example.com/contact/{id} /*delete */


this code is user for contactController
PHP Code:
$routes->resource('contact'); 
=> contactfile is sub Resource  
i need these urls bellow according to  restful api rules  


http://api.example.com/contact /{id}/contactfile* get*/ 
http://api.example.com/contact /{id}/contactfile* post*/  
http://api.example.com/contact/{id} /contactfile{id}/* put*/
http://api.example.com/contact/{id} /contactfile/{id}/*delete */

and this code is no  good  for sub resource 

Code:
$routes->resource('contactfile');


this is work but not best way handle  request   it need two time request for one for Parent(contactCtl) then childern(contacFileCtl) 


here is  code with angular 10  Get Http Request  its nested request 
 
 

Code:
public getSingelPost(id: number) {
  
    return this.http.get('http://localhost:8080/contact/1' + id).pipe(map((info: any) => {
     // console.log(info);
      return info.data;
    }),switchMap((info: any) => {
      // console.log(info);
      return this.http.get('http://localhost:8080/contact/1/contactfile/1');
    }), catchError(error => {
      console.log(error);
      return throwError('erors');
    }));
  }





please help me  thnak ci funs

Why This Solution Works on CI3 and PHP 7.1+

$
0
0
I have a CI3 (3.1.11) project on IIS with PHP 7.0 . It works without any error for years. Today i need to upgrade my projects environment to PHP 7.2.7 and then very big session problem occured.

When i login to my system with ajax request, after redirect to main page everything about session has been reset.

I searched this forum and stackoverflow for this problem, writing a lot of solutions at them.

I tried to delete all of system folder and then downloaded latest from here and moved new system folder to my projects folder but it isn't solved anything.

When i downgrade to 7.0 everything works perfectly but when i change php version to 7.2 session fails to save.

A lot of hours later, i found a solution writes as this:

Code:
if you are working in CI 3.x and just upgraded your server php version to php 7.x Go to system/libraries/Session/session.php at Line no 281 and replace ini_set('session.name', $params['cookie_name']); by ini_set('session.id', $params['cookie_name']);

i don't understand but this solution solved my problem but i don't like to touch system folder files.

And now: are there any different solution to solve this problem without touch system folder files? If there isn't, why don't you merge this solution to your hard code of CI?

Please allow update_batch with multiple keys

$
0
0
Example:
I have a MySQL table order_details (order_id, product_id, price).
Keys are: order_id and product_id.

Codeigniter should allow update batch with multiple keys like this:

PHP Code:
$data = array(
array(
'order_id' => 1,
'product_id' => 1,
'price' => 99
),
array(
'order_id' => 1,
'product_id' => 2,
'price' => 80
)
);
$this->db->update_batch('order_details'$data, array('order_id''product_id') ); 

Please add this feature.

How to Sanitize data in FilterInterface CI4

$
0
0
Hi,

Can somebody tell me how to use FilterInterface in modifying request before using it in the Controller? I want to sanitize or to remove unwanted characters in the data before using it in my Controller.

Here is the sample of my code: 

Filter:

PHP Code:
namespace App\Filters;

use 
CodeIgniter\HTTP\RequestInterface;
use 
CodeIgniter\HTTP\ResponseInterface;
use 
CodeIgniter\Filters\FilterInterface;

class 
SanitizeFields implements FilterInterface
{

    protected $session;

    public function before(RequestInterface $request$arguments null)
    {
        $request->getVar('number_only'FILTER_SANITIZE_NUMBER_INT);
    }

    public function after(RequestInterface $requestResponseInterface $response$arguments null)
    {
        // Do something here
    }



Controller: 
PHP Code:
//controller
public function getData()
{
    echo $this->request->getVar('number_only');


Is it possible to sanitize the value of number_only variable from "123abc456" to "123456"? 

Thank you!

Query binding

$
0
0
Hi everyone,

First, sorry if the question has already been asked (which is quite possible) : i did not find it.
I have a small problem with query binding : i don't need to execute the query with binding and get a result set, i simply need the computed query, something like 

PHP Code:
$str $this->db->getComputedQuery($query$dataToBind); 

Thanks

How to use Minify in Codeigniter 4 - Namespace Issues

$
0
0
Hi,

I am trying to use matthiasmullie/minify in Codeigniter 4. But so far I am getting errors due to wrong namespacing. Following is what I did so far:

I copied whole unzipped folder in Library: Libraries/Mathia

I added following in Config/Autoload.php
PHP Code:
'MatthiasMullie'      => APPPATH 'Libraries/Mathia/src'

In a controller I used following code:
PHP Code:
use MatthiasMullie\Minify

Then I used following code to use it but I got errors, file not found
PHP Code:
$minifier = new Minify\CSS(); 

Kindly advise how to use it correctly.

Regards

Note: I do not want to use composer, kindly advise how to manually integrate Minify in Codeigniter 4.

Setting Up CodeIgniter in Eclipse

$
0
0
Hey all,

I'm trying to get started with CI but it doesn't seem compatible with Eclipse.

I used the composer command from the tutorial

Quote:composer create-project codeigniter4/appstarter ci-news


and then created a new Eclipse project from my ci-news folder, but this gives me 200 errors. The first few for example are:


Quote:Description Resource Path Location Type
\Doctrine\Common\Persistence\ObjectRepository cannot be resolved to a type EntityPopulator.php /ci-news/vendor/fzaninotto/faker/src/Faker/ORM/Doctrine line 236 PHP Problem
\pcov cannot be resolved to a type PCOV.php /ci-news/vendor/phpunit/php-code-coverage/src/Driver line 38 PHP Problem
\PHPUnit_Framework_MockObject_MockObject cannot be resolved to a type AbstractVersionConstraintTest.php /ci-news/vendor/phar-io/version/tests/Unit line 20 PHP Problem
\PHPUnit_Framework_MockObject_MockObject cannot be resolved to a type ExtensionTest.php /ci-news/vendor/phar-io/manifest/tests/values line 33 PHP Problem
\Predis\Client cannot be resolved to a type PredisHandler.php /ci-news/vendor/codeigniter4/framework/system/Cache/Handlers line 73 PHP Problem
14 cannot be resolved to a type Company.php /ci-news/vendor/fzaninotto/faker/src/Faker/Provider/pl_PL line 59 PHP Problem
amount cannot be resolved to a type FileContent.php /ci-news/vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/content line 60 PHP Problem
amount cannot be resolved to a type SeekableFileContent.php /ci-news/vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs/content line 94 PHP Problem
amount cannot be resolved to a type vfsStreamFile.php /ci-news/vendor/mikey179/vfsstream/src/main/php/org/bovigo/vfs line 192 PHP Problem



What should I do here?

Best way to create a notifications system in nav bar

$
0
0
Hi,

I want to create a "notification system" with an icon in the nav bar that shows the notifications.

This notifications shows in every page.

What is the best way to do this?

I have 2 different "base controller". 1 for logged users and 1 for not-logged users.

Regards.

change username in this forum

$
0
0
good evening everybody,

is there a way to change the own username in this forum?
I've searched in the profile settings, but i dont found a setting to change my name.

br

sqlsrv with CI 3

$
0
0
I've had some good success with updating my code from php 5.6 to php 7.x and updating the driver to use sqlsrv. I typically try to use the CI query method and it works most of the time. I noticed that something weird happens when I try to backup a database though. If I change my code to use sqlsrv_query instead of $this->db->query it works much better. If I try to use the CI query method the backup file will be created and then gets deleted. 

I don't see any errors on the server side or php side but the SQL Server just says it failed to backup the database. I would rather use the CI method as I can hide the password in the database.php instead of being in the code directly. 

Has anyone else seen this behavior?

two foreach connect

$
0
0
Hello everyone,
I have a question.
In my website I often have to link two different "foreach".
I usually do it like this

PHP Code:
foreach ($view_category_main as $main):
    
$SQL "SELECT * FROM db_todo_mission WHERE db_todo_mission.tb_todo_mission_main = ".$main['category_id']." GROUP BY db_todo_mission.tb_todo_mission_sub";
    
$query $this->db->query($SQL);
    foreach (
$query->result() as $sub):
        echo 
$sub->tb_todo_mission_sub;
    endforeach;
endforeach; 


Now i wonder if there is a more elegant way to store it in modal and then have it retrieved?

linking to a MySQL DB in CI4?

$
0
0
I want to create a DB (MySQLl 5.x) and connect it to my CI4 site.  I obviously know how to make the actual database, but not how to link it to CI.  I assume I create some sort of config.php file with my connection details, then include this in my site files.  I'm just not sure about the back end stuff.  Anyone have any pointers?  Thanks!

creating a registration system with CI4, and why is CI "better"?

$
0
0
I'd like to create a registration system (with e-mail validation and remember me) and then present certain pages to the visitor based on being logged on or not.  How can I get started?  I'm still new to PHP, and have never used a framework before.

Also, why is using CI "better" than just pure PHP?

Any help or ideas would be most appreciated!

404 on routes in sub folder

$
0
0
I inherited a codeigniter website, and upgraded codeigniter. Figured out the controller files have to start with capital letters, and I got most of the routes and views working again. Except for the Admin portion of the site. The routes for this portion is not in the routes.php file, but in a different file. And the controllers is in a sub directory called admin, which I renamed to Admin. So even though there is for example an entry:

PHP Code:
$route['admin'] = 'admin/admin/index' 

When I go to /admin I get 404, and logs show:
Code:
404 Page Not Found: Admin/admin

I've even tried putting eg
PHP Code:
$route['admin/login'] = "admin/admin/login"
in the routes.php file, but I still see in the logs
Code:
404 Page Not Found: Admin/admin
even though:

Code:
$ grep admin config/routes.php
route['admin/login'] = "admin/admin/login";
$ grep login controllers/Admin/Admin.php
    public function login()
How can I troubleshoot these 404 errors in order to properly load the routes in the sub folder?

How to use all methods of PHP Redis with Codeigniter 4

$
0
0
Hi all

I am trying to use redis cache in Codeigniter 4 with PECL PHP REDIC . 

Codeigniter 4 documentation shows only few methods like GET, SAVE, DELETE. 

I tried to use SET but it did not work. How to use all available methods of PHP REDIS like set, hSet, etc?

Regards

How simply work session ?

$
0
0
Hello,

I try to use session() but I get this error :
{PHP internal code}   —  CodeIgniter\Debug\Exceptions->shutdownHandler ()

I want to set session globally in BaseController and simply use session() to set my session.

My session is working if I use php superglobal $_SESSION[] but impossible to use session().

Please give me the code to insert into BaseController, normally I can simply put code like this in my controller :

session('test')='my test';
echo session('test');

No ?

I'm lost trying many many thing !
Viewing all 14353 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>