how to get limited number of records and order by rand ? |
Hi,
I am 100% new to CI 4 and fairly new to MVC. I did the Build Your First Application and from that I am trying to make my project. I created a homepage in which I have to load banners and using the example code from news tutorial I got all the banners but I want to get them randomly and also I want to limit the number of banners I get. Right now I am getting all findAll(); so according to this my question is: 1. How to get 5 banners randomly 2. How / Where (in which folder) to add custom js / css and other files ? Thanks.
1)you might be able to do something like lever use of
Code: rand($min,$max) and use codeigniter built in models utility : Code: public function getOne($id) you would have to do count but id might not start with min nor end with max. 2)this is how i set out my assetts: Code: public eg in js I have Code: js
One more question would be how to use composer to install other 3rd party resources which I have to use???
ok there is a handy site for software that you can get via composer : https://packagist.org/
lets say you want to allow people to download the text version of a blog you have. So i enter html2pdf in search box of packagist : Top of the list i see : spipu/html2pdf i left click on it and then see: composer require spipu/html2pdf thats tells me that if i have composer set up correctly , i open a terminal and cd to root directory of web dev and run: Code: composer require spipu/html2pdf i then see in vendor directory: spipu and also notice a chnage in composer.json Code: "spipu/html2pdf": "^5.2", some software obtained via composer have deps , and to make sure you have them, just run after running Code: composer require spipu/html2pdf A few things to note here. If your using appstarter, vendor directory is where stuff goes and thus is critical to keep. System directory if its there is more for ref as far as i can see. Once you have software , its now easy when you need to update. For instance ig a new version of codeigniter appears you can run Code: composer update codeigniter4/framework to avoid getting dev you can use --no-dev oh one more thing, composer has autoload so it knows where the software is : to use for example spipu in a controller i found all i had to do was put at top of controller: Code: use Spipu\Html2Pdf\Html2Pdf; Code: $html2pdf = new Html2Pdf(); if you manually set something up not using composer then you have to use the autoloader of CI4 which is : app/Config/Autoload.php if it has a namespace use $psr4 = [ ] if not there is a class map section below that .That should be enough to get you going ? |
Welcome Guest, Not a member yet? Register Sign In |