How to get entity_guid from JS for send to the server.

Dani MR Posted in Beginning Developers 1 decade ago

I make a request from JS like:

 $.post("<?php echo ossn_site_url("action/optiontrips/getmaptrips", true); ?>", function(trips){   

Server:

public function getMapTrips() {
		if(empty($this->entity_guid)) {
					return false;
			}
			$params           = array();
			$params["from"]   = "ossn_trips";
			$params["params"] = array(

					"e.guid ="{$this->entity_guid}""
			);
			$data = $this->select($params);
			
			if($data) {
					$entity = arrayObject($data, get_class($this));
					return $entity;
			}	
			return $this->select($params, true);

But return "false" from 3rd line

Can you help me?

Many thanks

Replies
Spanish Dani MR Replied 1 decade ago

You're the best!!

I will make a new git push ;)

Thanksss a lot

Indonesian Arsalan Shah Replied 1 decade ago

The code you posted is wrong, the correct one is :

public function getMapTrips() {
      $user = ossn_loggedin_user()->guid; 
        if(empty($user)) { 
                return false;
        }
        $params           = array();
        $params["from"]   = "ossn_trips";
        $params["wheres"] = array(
                "guid="{$user}""
        );
        return $this->select($params, true);
}
Spanish Dani MR Replied 1 decade ago

The diference is it only the name of the column in db?

I try with "guid" but i can get it $user = ossn_loggedin_user()->guid;

public function getMapTrips() {
		$user = ossn_loggedin_user()->guid; //This is working
		
		//if(empty($this->entity_guid)) {
		if(empty($user)) { //This is working
					return false;
			}
			$params           = array();
			$params["from"]   = "ossn_trips";
			$params["params"] = array(

					//"guid ="{$this->entity_guid}""
					"guid ="{$user}"" //This is working
			);
			
			$data = $this->select($params);
			
			if($data) {
					$entity = arrayObject($data, get_class($this));
					return $entity;
			}	
			
			return $this->select($params, true);

Now only have a problem, only return 1 object no 4!!??

Indonesian Arsalan Shah Replied 1 decade ago

There is no e.guid in your table, it should be guid

     $params["params"] = array(
         "guid ="{$this->entity_guid}""
     );
Spanish Dani MR Replied 1 decade ago

CREATE TABLE IF NOT EXISTS ossn_trips (
id_trip int(11) NOT NULL AUTO_INCREMENT,
guid int(11) NOT NULL,
title text COLLATE utf8_spanish_ci NOT NULL,
description text COLLATE utf8_spanish_ci NOT NULL,
longitude float(10,6) NOT NULL,
latitude float(10,6) NOT NULL,
PRIMARY KEY (id_trip)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci AUTO_INCREMENT=5 ;

INSERT INTO ossn_trips (id_trip, guid, title, description, longitude, latitude) VALUES
(1, 1, 'First trip to San Francisco', 'Few days in San Francisco City', 37.774929, -122.419418),
(2, 1, 'Visit to GooglePlex in Mountain View', 'Summit with others Google top contributors and communiy managers.', 37.386051, -122.083855),
(3, 1, 'First trip by bus to Rome in Italy', 'A week with friends', 53.349804, -6.260310),
(4, 1, 'Visit Google Dublín', 'Only 4 days in Dublin, nice experience.', 41.902782, 12.496366);

Thanks Again

Indonesian Arsalan Shah Replied 1 decade ago

Why do you need entity_guid in your custom table? if you shows us table structure we might can help you.