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

Validation Always Print Error Message

$
0
0
Here is my Controller

Code:
public function pagecreate()
   {
       $validation = $this->validate([
           'title' => 'required',
           'body' => 'required'
       ]);
       if (!$validation) {
           $data['page_heading'] = 'Create New Page';
           $data['content_view'] = 'Backend/Pages/Create';
           echo view('Backend/Themes/Base', $data);
       } else {
           $this->model->save(
               [
                   'title' => $this->request->getvar('title'),
                   'content' => $this->request->getVar('body')
               ]
           );
           return redirect()->to('');
       }
   }

Here is my Views
Code:
<div class="row">
   <div class="col-md-12">
       <div class="card-box">
           <h4 class="m-t-0 header-title"><?php echo $page_heading; ?></h4>

           <?= service('validation')->listErrors() ?>
           
           <?php echo form_open('admin/pages/create'); ?>

And issue is Views always print validation error message withour submiting form ?
The title field is required.
The body field is required.

Is there any problems with my code ?

Namespaced Tests

$
0
0
Has anyone experimented with namespacing tests in third-party packages? Like if I made a library and Jill includes it with `composer require mgatner/libfoo`, and I want to supply tests for the user to verify functionality, ensure stability, work with pipelines, etc... Do I provide a Tests folder they would need to copy into somewhere? Or can they run the namespaced tests right out of /vendor with CI4’s tests and PHPUnit?

extensions for an existing CI app (hooks)

$
0
0
Hi,

Let say, I have an CodeIgniter application that's going to be deployed in many sites. They all have the same needs (hence they use the same app), but they also have specific needs.
Is there a way to use "extensions" on a CodeIgniter application (the same way, we use "plugins" in WordPress, for instance - not the same as CI plugins) ?
Of course, I could use CI librairies to add the code, but I will still need to modify the existing application (for instance to add a new line in the application menu). I don't want to modify the CI application otherwise, I won't be able to release easily a new version.
In WordPress (and others) they solved this, by using hooks.
Is there something similar that could be used in CI ?


Thanks in adance,
L@u

[split] What’s Up

CI Nopb (Need some advice)

$
0
0
Hey guys

I have just taken over a site for a client which is built on CI by a previous company which I have never dealt with before - Once I uploaded to my server and got the site running the admin side did not allow me to log in anymore. It can tell I am a user with the correct credentials but it just redirects back on itself to the login page again.

Any help or advice would be appreciated and I am sorry for the vagueness with the information but I am a total novice with this.

Cheers

Josh

how to route country region state

$
0
0
so this is my first post and would like to know how i would create a route 

so i have a country controller.

localhost/country/india

this page displays a list of regions in india.

so i have a controller 

localhost/region/southernindia

i want my url to look like this

localhost/india/southernindia

what would be best practice

Descargar plantilla ya creada en word con phpword

$
0
0
Saludos comunidad, necesito ayuda con la librería phpword.

Necesito poder descargar una plantilla de word ya creada con la librería de phpword. Esta es mi función que esta en el controlador:

public function word(){
$phpWord = new \PhpOffice\PhpWord\PhpWord();
 
$section = $phpWord->addSection();
 
$section->addText('"Learn from yesterday, live for today, hope for tomorrow. '
. 'The important thing is not to stop questioning." '
. '(Albert Einstein)');
 
$section->addText('Great achievement is usually born of great sacrifice, '
. 'and is never the result of selfishness. (Napoleon Hill)',
array('name' => 'Tahoma', 'size' => 10));
 
$fontStyleName = 'oneUserDefinedStyle';
$phpWord->addFontStyle($fontStyleName,
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true));
         
$section->addText('"The greatest accomplishment is not in never falling, '
. 'but in rising again after you fall." '
. '(Vince Lombardi)',
$fontStyleName);
 
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Tahoma');
$fontStyle->setSize(13);
$myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
$myTextElement->setFontStyle($fontStyle);
 
$file = 'HelloWorld.docx';
header("Content-Description: File Transfer");
header('Content-Disposition: attachment; filename="' . $file . '"');
header('Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document');
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Expires: 0');
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$xmlWriter->save("php://output");
}

Can't make Dynamic Routes with Groups And Spacenames and Regex work

$
0
0
Hi,

I am having trouble defining my routes for my admin pages.

I have multiple Controllers in my app/Admin folder with Namespace App\Admin (including Dashboard and Order)

Here is an example Order.php :
Code:
<?php
namespace App\Admin;
use CodeIgniter\Controller;
 
class Order extends Controller{
   function index(){
       echo view('admin/order_view');
   }


What I wanted to achieve was :

Code:
$routes->get('/', 'Home::index');
$routes->group('admin', ['namespace' => 'App\Admin'], function($routes)
{
    $routes->get('/', 'Dashboard');
    $routes->get('([a-zA-Z_]+)', '$1');
}); 

to get the default index function of my \App\Admin\Order controller.

I did notice the $0, $1 ... syntax only works when there is at least one forward slash in front of my route "/([a-zA-Z_]+)" which I think is unfortunate.

I can easily show the Dashboard (example.com/admin) that is hardcoded but can't seem to get the Order controller (example.com/admin/Order or even example.com/admin/order) through the regex, although they are in the same namespace and folder.

It seems that you can use a lower case first letter when you want to get a controller through its filename, but when it comes to namespaces it's case sensitive or am I wrong?

I also tried

Code:
$routes->get('/', 'Home::index');
$routes->group('admin', ['namespace' => 'App\Admin'], function($routes)
{
    $routes->get('/', 'Dashboard');
});

$routes->get('admin/([a-zA-Z_]+)', '\App\Admin\$1'); 


but alas it doesn't work either. I was hoping to use the group feature so that I can easily add other routes through regex like :
Code:
$routes->get('([a-zA-Z_]+)/edit' , '$1::edit' ); 

or

Code:
$routes->get('([a-zA-Z_]+)/add' , '$1::add' ) 

which doesn't seem too farfetched.

Can't use a cache?

$
0
0
Hi Guys,

Just checking:  since my websites have information like user names and amount ordered in headers, and are full of ajax calls and modal windows about the customer's order,  I'm thinking that I can't use caching.

Is that right?  Or am I missing something.

Thanks!

John

CLI No Newline

$
0
0
I'd love a way to suppress the newline character from CLI::write, so you can do things like:
Generating new widget...

then in a bit:
Generating new widget... Done!

CLI:write is already pretty darn loaded with parameters, so maybe a new command?

[split] Multi-language support (Project Update 2019.01.04)

$
0
0
Will CI 4 support multiple languages via url out of the box?

Something like:



Code:
exmaple.com/en-US/controler
exmaple.com/en-GB/controler
exmaple.com/pl-PL/controler

or:
Code:
exmaple.com/en/controler
exmaple.com/pl/controler

Call to undefined function CAST()

$
0
0
Hi! Im having an error in using the cast function in my model. Does cast() works in codeigniter?

Problems loading a style css from another directory

$
0
0
Hello!
Today I load a css dynamically as follows:

PHP Code:
   function addStyle($file '')
 
   {
 
       $ci = &get_instance();
 
       $header_css $ci->config->item('header_css');

 
       if (empty($file) || !$file) {
 
           return;
 
       }

 
       if (is_array($file)) {
 
           foreach ($file as $item) {
 
               $header_css[] = $item;
 
           }

 
           $ci->config->set_item('header_css'$header_css);
 
       } else {
 
           $header_css[] = $file;
 
           $ci->config->set_item('header_css'$header_css);
 
       }
 
   

This works fine, but when I try to load into another directory, the function can not find the style, causing error.
Does anyone know of any way to dynamically load the css being able to be in another directory as well?

Thank you!

Permission Handling Library

$
0
0
Hi all! Hopefully you've seen my other libraries thread, so you know the routine. This one is a little different, in that the original library was a dual authentication/authorization library but both of these realms have changed so drastically since CI3 neither would work well as a direct "port". There are also other libraries in the works to be robust and comprehensive solutions (see for example @kilishan's Myth:Auth) so I haven't been sure if I will rework the original library at all.
That said, one of my favorite aspects of the original library was object permissions - think Unix "chmod" permissions for your models & instances. This library couples traditional named permissions with a CI4 take on object permissions. So, I give you:

Tatter/Permits - out-of-the-box permission handling for CodeIgniter 4

Basic usage:

1. Install with Composer: `> composer require tatter/permits`
2. Update the database: `> php spark migrate:latest -all`
3. Extend your models: `class JobModel extends Tatter\Permits\Models\PModel;`
4. Ready to use! `if ($jobs->mayCreate()) ...`
5. (Optional) Add overrides: `> php spark permits:add` or `> php spark permits:add deleteJobs groups 7`


This library is much more involved than the previous libraries, and has more room to grow. I am eager for feedback, suggestions, and contributions - feel free to respond here or on GitHub (https://github.com/tattersoftware/codeigniter4-permits).
Thanks for reading!

How to send flashdata to a different session

$
0
0
Hi Team,

We are using CI v3 with a file based session management scheme.

We have a situation where a user initiates a web transaction which results in a callback to our ubuntu apache2 web server. The callback is dealt with by its own controller.

What I would like to do is somehow connect the new instance back to the originating session so that I can set some flashdata to be displayed on the next page rendering.

In the bad old days session_id was available in userdata() but now its not. The callback has the originating session id as part of the URL, and I am struggling to find any help on how to achieve what I want.

I read something about using session_id() in PHP but it made reference to doing this before session_start() and we autoload the session library.

Can it be done please, and if so how?

Help appreciated, regards Paul

Message Lib instead of Mail only?

$
0
0
Hello everyone,

I wan't to open one thread about the Mail system in CI 4. 
Those days sending message / notification is possible not only by e-mail but and by many other gateways "SMS, 3rd party apps (FB, Google, etc..)"

Wouldn't it be better if in CI 4 instead of Mail library there is Message library with email as the only base supported gateway ? 
This way anyone will be able to add any kind of message gateways and to use it by standard framework class/methods following just a base driver interfaces..

In most of the cases a Message (mail or other) has very common things : Sender, Receiver, Message, Attachment.. 
Of course there will be some differences as some of the gateways will require to be authenticated (maybe some key or other) but this will be handled by the drivers and not by the base Message class..

Thank you!

Tables are Posts and Tags.

$
0
0
Tables are Posts and Tags. 

One Post has Many Tags. And One Tag has Many Posts. A so-called 'Many-to-Many' relationship. 

This is solved with a intermediate table (post_tag) with id for post_id and tag_id and a created_at row. 

Now, How do you handle this in CodeIgniter? 

And before you answer. I also wish to learn how to handle updating records in intermediate table. 

As in, I remove a Post or I add a new Tag to a Post. 

Thanks, [Image: smile.gif]

I cant fetch the entire content of the select box

$
0
0
When I try to fetch the data in a form, only the first word of the select box captured. see images for more details.


.png   AcerS3 31.png (Size: 144.6 KB / Downloads: 0)

where_in null and 1

$
0
0
->where_in('Login',array(null,1))

not working pls help me.

.png   sql.png (Size: 4.45 KB / Downloads: 6)

.png   where_in.png (Size: 2.71 KB / Downloads: 4)

Rather pointless error message

$
0
0
I'm trying out CI4 beta 1.

The demo page works, but when I try to retrieve stuff from the database it crashes with this message:

Quote:Whoops!

We seem to have hit a snag. Please try again later...

How to turn this off so that I can see actual error messages?

Setting

Code:
SetEnv CI_ENVIRONMENT development


has no effect.
Viewing all 14343 articles
Browse latest View live


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