Welcome Guest, Not a member yet? Register   Sign In
How to use view to load a CSS file
#1

I am delighted that the CI4 Alpha Version has been released and decided to rewrite some very, very old scripts that started even before CI2 was released.

The old script has been modified extensively and currently uses CI_VERSION: 3.1.8

This script was acceptable but now fails and curious to know the correct way to load the variable:



PHP Code:
$data['styleTest'] = view('incs/styleTest.css'$datatrue); 

Error Message:
Argument 3 passed to view() must be of the type array, boolean given, called in /home/john/www/test-ci4-version

I have tried numerous options and this KLUDGE works but I would far prefer to use the correct method of loading the file:

KLUDGE:
PHP Code:
 $tmp file_get_contents'/incs/styleTest.css' );
    $data['styleTest'] = $tmp
Reply
#2

Er, nothing has been released yet, though we inch closer.

Having said that, CI4 uses the render() method of a View or Parser object. There is no view(...) method in the RenderInterface.
See https://bcit-ci.github.io/CodeIgniter4/g...derer.html
Reply
#3

(This post was last modified: 05-21-2018, 12:56 AM by John_Betong.)

(05-19-2018, 09:27 PM)ciadmin Wrote: Er, nothing has been released yet, though we inch closer.

Having said that, CI4 uses the render() method of a View or Parser object. There is no view(...) method in the RenderInterface.
See https://bcit-ci.github.io/CodeIgniter4/g...derer.html

Whoops, I mistook the "pre-alpha" to be alpha.

I followed the link and failed to understand the intricacies. Numerous script snippets were tried from the provided help page. Unfortunately none work? I know the Help pages are under construction... would it be more helpful to supply working examples that can be analysed to make the help pages more easily understood? A good provided example is the Home Class which uses the view method to render the "welcome_message" View. Personally I would prefer to be shown more options rather than a minimilistic version. 

My dilemma is that in all prior versions of CI, passing non php pages via the view method worked satisfactorily... as long as the default php file extension was supplied. Numerous parameters could then be passed to a common view (via $data) thus reducing the number of views. Site wide small changes could be tested and rolled back if problems were encountered. Ideal when trying to implement AmpProject pages. DRY principle springs to mind. 

>>> Off Topic
Is there:
1. an itemised list of features required before the CI4 Alpha is released?
2. also a list which states what can be used in the current release.

I believe the second item will encourage more users to try an Alpha version resulting in useful error reporting feedback. 

Aiming for an ideal platform is impeding the Alpha release because of daily Web security problems Sad
>>> Off Topic

Edit:
Removed and made a separate thread.
Reply
#4

Your error states Argument 3 passed to view() must be of the type array, boolean given. A look at the code for the view() function shows it's looking for an $options array, which really only has one valid value at the moment: 'saveData'. Where in the manual is it stating to pass a true/false as the third parameter? We need to update that if you can show us where.
Reply
#5

(This post was last modified: 05-21-2018, 09:05 AM by John_Betong.)

(05-21-2018, 05:46 AM)kilishan Wrote: Your error states Argument 3 passed to view() must be of the type array, boolean given. A look at the code for the view() function shows it's looking for an $options array, which really only has one valid value at the moment: 'saveData'. Where in the manual is it stating to pass a true/false as the third parameter? We need to update that if you can show us where.

From the Online Manual:

/*
Maybe incorrect Boolean $saveData - should be array['save'=true]; ?
*/
https://bcit-ci.github.io/CodeIgniter4/g...t=savedata
$data = [
        'title'   => 'My title',
        'heading' => 'My Heading',
        'message' => 'My Message'
];
echo view('blogview', $data, ['saveData' => true]);
Additionally, if you would like the default functionality of the view method to be that it does save the data between calls, you can set $saveData to true in application/Config/Views.php.


/*
Uses Boolean
*/
https://bcit-ci.github.io/CodeIgniter4/g...t=savedata
CodeIgniter\View\Parser
render($view[, $options[, $saveData=false]]])


/*
Uses Boolean
*/
https://bcit-ci.github.io/CodeIgniter4/g...t=savedata
CodeIgniter\View\View
  render($view[, $options[, $saveData=false]]])
      Parameters:
          $view (string) – File name of the view source
          $options (array) – Array of options, as key/value pairs
          $saveData (boolean) – If true, will save data for use with any other calls, if false, will clean the data after rendering the view.


/*
Uses Boolean
*/
https://bcit-ci.github.io/CodeIgniter4/g...t=savedata
renderString($view[, $options[, $saveData=false]]])
  Parameters:
      $view (string) – Contents of the view to render, for instance content retrieved from a database
      $options (array) – Array of options, as key/value pairs
      $saveData (boolean) – If true, will save data for use with any other calls, if false, will clean the data after rendering the view.


//================================================
I managed to solve the problem of using View to load a CSS file:

CodeIgniter\View\View::render ==> Line: 170

PHP Code:
# echo  __method__ .' ==> Line: ' .__line__ ;die;

# IF AND ONLY IF APPEND .php WHEN NO FILE EXTENSION EXISTS
 
 ifstrpos$view'.' ) ):
 
   # ASSUME FILE OK AND DO NOT APPEND .php
 
     $this->renderVars['view'] = $view;
 
 else:    
 
  # ORIGINAL SCRIPT 
 
    $this->renderVars['view'] = str_replace('.php'''$view) . '.php';
 
 endif
Reply




Theme © iAndrew 2016 - Forum software by © MyBB