Fix an anchor issue |
Hello all!
I uploaded code from git into my site but having an issue anchoring the controller to view. This is my anchor: <?= anchor('chat/index','Chat');?> This is the controller/function that Im trying to connect: class Chat extends Controller { function Chat() { parent::Controller(); $this->load->database('cultured_codeignite'); $this->load->model('mod_chat'); $this->load->library(array('session', 'authentication')); } function index() { //outsiders keep out $this->authentication->sentry(); $ctr = 0; //get all chat messages from buddy $username = $this->session->userdata('username'); $recipient = $this->session->userdata('recipient'); $fetchchat = $this->mod_chat->fetchchat($username, $recipient); $chatreverse = ''; //reverse results of chat, bottom message is latest foreach ($fetchchat as $chatorig) { $chatreverse[$ctr]['username'] = $chatorig->username; $chatreverse[$ctr]['message'] = $chatorig->message; $time = explode(' ', $chatorig->time); $reformat_time = date("g:i a", strtotime($time[1])); $chatreverse[$ctr]['time'] = $reformat_time; ++$ctr; } $data['chat'] = ''; $data['buddy'] = $this->session->userdata('recipient'); $buddyimage = $this->mod_chat->get_buddy_image($this->session->userdata('recipient')); $data['buddyimage'] = $buddyimage[0]->image; //throw messages to view if (is_array($chatreverse)) { $users['username'] = $username; $users['recipient'] = $recipient; $this->mod_chat->message_read($users); $data['chat'] = array_reverse($chatreverse); } $this->load->view('view_chat', $data); } The viewer is view_chat that Im trying to connect to. How do I get this to work? , Mekaboo
Your constructor is using the old style.
PHP Code: // change this Try that and see if it works. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-24-2019, 10:10 PM)php_rocs Wrote: @Mekaboo, Hey! I get a 404 error saying that the page is not found. Basic error..the page isnt loading at all. Im trying to figure out if its because of the function. (06-25-2019, 03:46 AM)InsiteFX Wrote: Your constructor is using the old style.Unfortunately it didnt help, Im still getting a 404 page dont exist code. Trying to figure out how to fix the function.
@Mekaboo,
I need to see what anchor value is being displayed on the page. Is it something like... https://yoursite.com/index.php/chat/index If so, then try removing the index and see if that works. Like this <?= anchor('chat','Chat');?> Also, I noticed that you didn't load the url helper ( https://www.codeigniter.com/user_guide/h...elper.html )
Thank ya all! I tried various ways to correct things from copy/paste from one controller to another as well as doing the same process for the models. Parts worked but not all. I looked up alternatives and found this one:
https://www.sourcecodester.com/php/6318/...mysql.html Had the "Undefined Variable error but this time I seem to fix on my own (WooHoo)..now its time to test. Thank you all for the help,it means alot |
Welcome Guest, Not a member yet? Register Sign In |