I have custom library and need to set limit start for list view records from this library.
Code is as follows:
$limitStart = $input->json->get('limit_start');
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
$model->setState("list.limit", $limitStart);
I did this but it's set default value to zero.
Can we override the limit start in joomla.
Thanks in advance.
I think you need to use following method to set the limitstart
$limitStart = 5;
$app = JFactory::getApplication();
$app->setUserState($this->context . '.limitstart', $limitStart);
Yes Can override the limitstart for your own library joomla framework
please flow this way
Open =>joomlaFile/configuration.php/for this code line no "7" default set 20
public $list_limit = '20'
Can you change to your Own PageLimit
public $list_limit = '5'
//simply read this
$config = JFactory::getConfig();
$limitStart = $config->get('list_limit');
you need system plugin to do this. see example for native tags component (the condition is needed to avoid rune code on wrong place )
public function onAfterRoute()
{
$app = JFactory::getApplication();
if ($app->input->getRaw('option') == 'com_tags' && $app->input->getRaw('view') == 'tag') {
$app->set('list_limit', 12);
}
}
Related
im quite new in laravel framework, and im from codeigniter.
I would like to add new key and value from database
static function m_get_promotion_banner(){
$query = DB::table("promotion_banner")
->select('promotion_banner_id','promotion_link','about_promotion')
->where('promotion_active','1')
->get();
if($query != null){
foreach ($query as $key => $row){
$query[$key]['promotion_image'] = URL::to('home/image/banner/'.$row['promotion_banner_id']);
}
}
return $query;
}
that code was just changed from codeigniter to laravel, since in codeigniter there are no problem in passing a new key and value in foreach statement
but when i tried it in laravel i got this following error :
Indirect modification of overloaded element of Illuminate\Support\Collection has no effect
at HandleExceptions->handleError(8, 'Indirect modification of overloaded element of Illuminate\Support\Collection has no effect', 'C:\xampp\htdocs\laravel-site\application\app\models\main\Main_home_m.php', 653, array('query' => object(Collection), 'row' => array('promotion_banner_id' => 1, 'promotion_link' => 'http://localhost/deal/home/voucher', 'about_promotion' => ''), 'key' => 0))
please guide me how to fix this
thank you (:
The result of a Laravel query will always be a Collection. To add a property to all the objects in this collection, you can use the map function.
$query = $query->map(function ($object) {
// Add the new property
$object->promotion_image = URL::to('home/image/banner/' . $object->promotion_banner_id);
// Return the new object
return $object;
});
Also, you can get and set the properties using actual object properties and not array keys. This makes the code much more readable in my opinion.
For others who needs a solution you can use jsonserialize method to modify the collection.
Such as:
$data = $data->jsonserialize();
//do your changes here now.
The problem is the get is returning a collection of stdObject
Instead of adding the new field to the result of your query, modify the model of what you are returning.
So, assuming you have a PromotionBanner.php model file in your app directory, edit it and then add these 2 blocks of code:
protected $appends = array('promotionImage');
here you just added the custom field. Now you tell the model how to fill it:
public function getPromotionImageAttribute() {
return (url('home/image/banner/'.$this->promotion_banner_id));
}
Now, you get your banners through your model:
static function m_get_promotion_banner(){
return \App\PromotionBanner::where('promotion_active','1')->get();
}
Now you can access your promotionImage propierty in your result
P.D:
In the case you are NOT using a model... Well, just create the file app\PromotionImage.php:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class PromotionImage extends Model
{
protected $appends = array('imageAttribute');
protected $table = 'promotion_banner';
public function getPromotionImageAttribute() {
return (url('home/image/banner/'.$this->promotion_banner_id));
}
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'promotion_banner_id','promotion_link','about_promotion','promotion_active'
];
just improving, in case you need to pass data inside the query
$url = 'home/image/banner/';
$query = $query->map(function ($object) use ($url) {
// Add the new property
$object->promotion_image = URL::to( $url . $object->promotion_banner_id);
// Return the new object
return $object;
});
I've been struggling with this all evening, and I'm still not sure what my problem is.
I've used ->get() to actually execute the query, and I've tried by ->toArray() and ->jsonserialize() on the data and it didn't fix the problem.
In the end, the work-around I found was this:
$task = Tasks::where("user_id", $userId)->first()->toArray();
$task = json_decode(json_encode($task), true);
$task["foo"] = "bar";
Using json_encode and then json_decode on it again freed it up from whatever was keeping me from editing it.
That's a hacky work-around at best, but if anyone else just needs to push past this problem and get on with their work, this might solve the problem for you.
I'm trying to insert a file into TYPO3 db through frontend using core functions or FileRepository, exactly into sys_file table.
While investigating I've seen few solutions like,
$storageRepository = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
$storage = $storageRepository->findByUid(1);
$fileObject = $storage->addFile('/tmp/myfile', $storage->getRootLevelFolder(), 'newFile');
echo $fileObject->getIdentifier(); // Should output "/newFile"
But I still can't find this addFile() in storageRepository class. Am I missing some thing here?
The line $storageRepository->findByUid(1) return a ResourceStorage Object with the Method addFile().
Here is a Documenttion of this class.
https://typo3.org/api/typo3cms/class_t_y_p_o3_1_1_c_m_s_1_1_core_1_1_resource_1_1_resource_storage.html
#mario Thanks. By the way I've achieved what I planned. Here's what I did..
public function uploadFile($uploadedfile) {
$storage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\StorageRepository');
$filePath = 'uploads/tx_fileupload/'.$uploadedfile['updata']['name'];
$title = $uploadedfile['updata']['name'];
$size = $uploadedfile['updata']['size'];
// Moving the physical file to destined folder
\TYPO3\CMS\Core\Utility\GeneralUtility::upload_copy_move($uploadedfile['updata']['tmp_name'],$filePath);
// Adding a record in sys_file_storage
$fileObject = $storage->createLocalStorage($uploadedfile['updata']['name'],$uploadedfile['updata']['tmp_name'],$filePath,'');
// Inserting file in sys_file
$repositoryFileObject = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($filePath);
return $repositoryFileObject;
}
Now moving onto adding corresponding sys_file_reference record.
I am trying to set a default value for select box in CakePHP. My options are accessed using a static function in the model which is defined like so
public static function purpose($value = null)
{
$options = array(
self::PURPOSE_HOMECONSUMPTION => __('Home Consumption', true),
self::PURPOSE_COMMERCIAL => __('Commercial', true)
);
return self::enum($value, $options);
}
// Constants for status attribute
const PURPOSE_HOMECONSUMPTION = '0';
const PURPOSE_COMMERCIAL = '1';
In my view, I fill the select box by calling this static function in this manner
echo $this->Form->input('purpose', array(
'type' => 'select',
'options' => Field::purpose()
Sure enough it picks the options but the default value is Home Consumption. I want to set it Commercial. I tried something like this in the controller
$this->request->data['Field']['purpose'] = Field::purpose(1);
But it doesn't work. Any ideas about how i can call the static function in the controller with the value set to Commercial.
Why are you using class constants and then NOT using them in the code?
Makes no sense to me.
You are on top resolving the integer value into the string. That also does not make sense if you want to use it as default value for a dropdown populated with your enum data.
The correct approach, logically, would be:
// The constant that holds the value 1
$this->request->data['Field']['purpose'] = ModelName::PURPOSE_COMMERCIAL;
Also note that constants should best be real integers, and you should be using tinyint(2) for the db type as mentioned on the blog code.
since a few hours i'm trying to implement the twitchAPI in my cake projet. a long time ago i made this little script in basic php.
$channelName = "gamespot";
$json_file = #file_get_contents("http://api.justin.tv/api/stream/list.json?channel={$channelName}", 0, null, null);
$json_array = json_decode($json_file, true);
#$json_array[0] && $json_array[0]['name'] == "live_user_{$channelName}";
#$title = $json_array[0]['channel']['status'];
#$game = $json_array[0]['meta_game'];
#$chanel_view = $json_array[0]['channel_count'];
#$totalchanelview = $json_array[0]['channel_view_count'];
but i don't know how to add this lines on my controller
For know i've just find this
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=manvsgame');
$twitch = json_decode($json);
$totalchanelview = $twitch[0]['channel_view_count'];
$this->set('twitch', 'totalchanelview');
}
but of course i've this error
Fatal error: Cannot use object of type stdClass as array in /Users/*/Desktop/Websites/**/app/Controller/UsersController.php on line 29
anyone can explain to me how i can use this API?
thanks in advance and have a nice day/night :)
okey first thanks to help me. i still have a little "logic problem"
my function is something like that:
public function twitch() {
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=gamespot');
$twitch = json_decode($json, true);
$this->set('json', $twitch);
}
but know, what can I write to my view to see my informations (like the title of my stream for exemple.
I test with
echo $twitch[0]['title']; (it's my line 1)
bit i've this error
Notice (8): Undefined variable: twitch [APP/View/Users/admin_dashboard.ctp, line 1]
$twitch = json_decode($json, true); // add true param
$twitch[0]['channel_view_count'];
adding true returns the data as an associated array instead
how can i make a database query with extbase to check if a database entry already exist? I know how to do that with php but not with extbase syntax.
I want to add a user to the database. That works. But the user should only be added if the regId doesn't already exist.
This is my code so far:
/**
* action registerDevice
* #param Tx_xxx_Domain_Repository_UserRepository $muserRepository
* #return void
*/
public function registerDeviceAction(){
$userRepository = $this->objectManager->get('Tx_xxx_Domain_Repository_UserRepository');
$user = $this->objectManager->create('Tx_xxx_Domain_Model_User');
$allUser = $this->userRepository->findAll();
if ( isset($_POST["regId"]) && $_GET['os'] ) {
$regDevice = $_POST["regId"];
$regMobileOs = $_GET["os"];
$user->setMobileOs( $regMobileOs );
$user->setFirstName('TEST');
$user->setRegId( $regDevice );
$this->userRepository->add($user);
$persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$persistenceManager->persistAll();
}
}
Thank you very much! :)
Best regards
Since Extbase 1.1 you can use the Magic Method find(One)ByProperty and countByProperty.
So, without creating a new method you can use something like:
if(!$this->someRepository->countByRegId($regId)) {
// there isnt a object with $regId yet
}